Rails
When immediately returning after calling
render
orredirect_to
, putreturn
on the next line, not the same line.
[link]# bad
render :text => 'Howdy' and return
# good
render :text => 'Howdy'
return
# still bad
render :text => 'Howdy' and return if foo.present?
# good
if foo.present?
render :text => 'Howdy'
return
end
Scopes
When defining ActiveRecord model scopes, wrap the
relation in alambda
. A naked relation forces a database connection to be
established at class load time (instance startup).
[link]# bad
scope :foo, where(:bar => 1)
# good
scope :foo, -> { where(:bar => 1) }