From http://www.cnblogs.com/rails3/