Fork me on GitHub

split your cap tasks into different files

10 Sep 2012

Richard Huang (flyerhzm@gmail.com)

Your capistrano deploy.rb file might become complicated with the growth of your application, contain more and more cap tasks, it would be better to split these tasks into different files according to the functionalities, which makes it easy to maintain, and they are more likely to be reused in the future. Read More

Tags 


rolling out with feature flags

02 Sep 2012

Richard Huang (flyerhzm@gmail.com)

Sometimes you may face the situation that some features will be released, but you are not sure if it is friendly to end user, or if it will lead to performance issues, at that time you should use what we called "feature flags" Read More

Tags 


use after_commit

02 May 2012

Richard Huang (flyerhzm@gmail.com)

Most developers use AR callbacks after_create/after_update/after_destroy to generate background job, expire cache, etc., but they don't realize these callbacks are still wrapped in database transaction, they probably got unexpected errors on production servers. Read More

Tags 


Protect mass assignment

06 Mar 2012

Richard Huang (flyerhzm@gmail.com)

Rails mass assignment feature is really useful, but it may be a security issue, it allows an attacker to set any models' attributes you may not expect. To avoid this, we should add attr_accessbile or attr_protected to all models. Read More

Tags 


Not use time_ago_in_words

10 Feb 2012

Richard Huang (flyerhzm@gmail.com)

It's very common for a rails developer to use time_ago_in_words to display time like "5 minutes ago", but it's too expensive to calculate the time in server side, you should utilize client cpu to calculate the time ago. Read More

Tags 


Name your model methods after their behavior, not implementation.

05 Dec 2011

Brasten Sager (brasten@brasten.me)

Business model methods should be named after the logic / business value they provide, not the implementation details. Violations to this practice tend to show up on ActiveRecord models. Read More

Tags 


Use cells to abstract view widgets

06 Nov 2011

Richard Huang (flyerhzm@gmail.com)

Rails developers always pay more attentions on models and controllers refactoring, they don't take care about views modularization, that makes view codes most difficult to maintain. Here I recommend you to use cells gem to write more reuseable, testable and cacheable view codes. Read More

Tags 


Optimize db migration

30 Oct 2011

Richard Huang (flyerhzm@gmail.com)

rails migration provides a convenient way to alter database structure, you can easily add, change and drop column to a existing table, but when the data in existing table are huge, it will take a long time to alter existing table, you should try to merge/optimize the db alter sql statements. Read More

Tags 


Restrict auto-generated routes.

19 Aug 2011

Andy Wang (wangyaodi@gmail.com)

By default, Rails generates seven RESTful routes(new,edit,create,destroy,index,show, update) for a resource, sometime the resource only needs one or two routes, so just user :only or :except while defining routes to speedup the routing. Read More

Tags 


Remove tab

04 Jul 2011

Richard Huang (flyerhzm@gmail.com)

Using tabs can mess up the spacing since some IDE's use 4 spaces for a tab, while others use 2, and some people don't use tabs at all, a mix of tabs and spaces causes things to not line up in most cases. Read More

Tags