Rails Best Practices
Trailing whitespace always makes noises in version control system, it is meaningless. We should remove trailing whitespace to avoid annoying other team members.implemented
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.
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.
Instead of loading an object with a before_filter you can use a more intelligent helper_method to get the main object for the controller context.
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 attributeimplemented
If you want to generate different urls according to different objects, you should use the polymorphic_path/polymorphic_url to simplify the url generation.
If you have to set some external gem's config options in /config/enviroment.rb, contain it within `if defined?` block
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.