Rails Best Practices

14 votes

24370 views

DRY bundler in capistrano

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.

implemented

Comments

flyerhzm

9 votes

13752 views

Put scripts at the bottom

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.

Comments

flyerhzm

11 votes

6555 views

use OpenStruct when advance search

use OpenStruct when advance search

Comments

alvin2ye

0 votes

56438 views

Fetch current user in models

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.

Comments

flyerhzm

16 votes

11253 views

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

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

implemented

Comments

Guillermo

13 votes

40059 views

Use STI and polymorphic model for multiple uploads

This is a flexible and reusable solution for multiple uploads, using STI model to save all the uploaded assets in one "assets" table and using polymorphic model to reuse "Asset" model in different uploadable models.

Comments

flyerhzm

2 votes

6639 views

to_s/to_s(:short)

override the to_s to make the method sensible instead of "display_name", "format_name"..

Comments

by yincan
yincan

10 votes

8785 views

Use css sprite automatically

Using css sprite can reduce a large number of http requests, so it makes the web page loaded much faster. It it painful to composite a lot of images manually, do it automatically.

Comments

flyerhzm

8 votes

24073 views

Use I18n.localize for date/time formating

For reliable formatting of a date/time string in the desired language, use I18n.localise, Time#strftime can cause u unnecessary headache.

Comments

by ngty
ngty

4 votes

19037 views

Use multipart/alternative as content_type of email

Rails uses plain/text as the default content_type for sending email, you should change it to multipart/alternative that email clients can display html formatted email if they support and display plain text email if they don't support html format.

implemented

Comments

flyerhzm