Fork me on GitHub

Use memoization

22 Nov 2010

Richard Huang

Memoization is an optimization technique used primarily to speed up computer programs by having function calls avoid repeating the calculation of results for previously-processed inputs. In rails, you can easily use memoize which is inherited from ActiveSupport::Memoizable. Read More

Tags 


Select specific fields for performance

19 Oct 2010

Richard Huang

In a system like forum, the title and body is displayed on show page, but only title is on index page. You should use select in query to speed up the query and save memory. Read More

Tags 


Use query attribute

03 Oct 2010

Richard Huang

Do you always check if ActiveRecord's attributes exist or not by nil?, blank? or present? ? Don't do that again, rails provides a cleaner way by query attribute Read More

Tags 


Generate polymorphic url

23 Sep 2010

Richard Huang

If you want to generate different urls according to different objects, you should use the polymorphic_path/polymorphic_url to simplify the url generation. Read More

Tags 


Use batched finder for large data query

09 Sep 2010

Richard Huang

If you want to do a large data query such as finding all the 10,000,000 users to send email to them, you should use batched finder to avoid eating too much memory. Read More

Tags 


DRY bundler in capistrano

02 Sep 2010

Richard Huang

There are a few posts told you how to integrate bundler into capistrano, but they are out of date now. After bundler 1.0 released, you can add only one line in capistrano to use bundler. Read More

Tags 


Put scripts at the bottom

30 Aug 2010

Richard Huang

Do you experience that your website renders slow due to loading a lot of javascripts, especially loading some third-party javascripts? Move script tags to the bottom of body can speed up the render of your website. Read More

Tags 


use OpenStruct when advance search

25 Aug 2010

Alvin Ye

use OpenStruct when advance search Read More

Tags 


Fetch current user in models

23 Aug 2010

Richard Huang

I don't remember how many times I need to fetch current user in models, such as audit log. Here is a flexible way to set the current user in and fetch the current user from User model. Read More

Tags 


Use say and say_with_time in migrations to make a useful migration log

19 Aug 2010

Guillermo Álvarez Fernández

Use say_with_time and say in migrations will produce a more readable output in migrations. And if use correctly it could be a helpful friend when something goes wrong because normally it is stored in the deploy log Read More

Tags