Rails Best Practices

5 votes

0 comments

1733 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.

deployment capistrano bundler

by flyerhzm flyerhzm

4 votes

0 comments

965 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.

view performance assets javascript

by flyerhzm flyerhzm

4 votes

0 comments

535 views

use OpenStruct when advance search

use OpenStruct when advance search

search view

by alvin2ye alvin2ye

2 votes

12 comments

2513 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.

model

by flyerhzm flyerhzm

7 votes

1 comments

585 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

migration

by Guillermo Guillermo

1 votes

12 comments

1599 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.

model upload

by flyerhzm flyerhzm

2 votes

5 comments

597 views

to_s/to_s(:short)

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

naming convention

by yincan yincan

2 votes

0 comments

874 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.

plugin performance css sprite convention assets

by flyerhzm flyerhzm

1 votes

3 comments

595 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.

I18n

by ngty ngty

3 votes

1 comments

860 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.

mailer

by flyerhzm flyerhzm