Rails
当调用
render或redirect_to后需要马上”返回”时,把return放到下一行, 不要放到同一行。
[link]# 错误render :text => 'Howdy' and return# 正确render :text => 'Howdy'return# still badrender :text => 'Howdy' and return if foo.present?# 正确if foo.present?render :text => 'Howdy'returnend
范围 (Scopes)
当定义 ActiveRecord 的模型 scopes 时, 把内容用大括号包起来。
如果不包的话, 在载入这个 class 时就会被强迫连接数据库。
[link]# 错误scope :foo, where(:bar => 1)# 正确scope :foo, -> { where(:bar => 1) }
