Rails

  • When immediately returning after calling
    render or redirect_to, put return on the next line, not the same line.
    [link]

    1. # bad
    2. render :text => 'Howdy' and return
    3. # good
    4. render :text => 'Howdy'
    5. return
    6. # still bad
    7. render :text => 'Howdy' and return if foo.present?
    8. # good
    9. if foo.present?
    10. render :text => 'Howdy'
    11. return
    12. end

Scopes

  • When defining ActiveRecord model scopes, wrap the
    relation in a lambda. A naked relation forces a database connection to be
    established at class load time (instance startup).
    [link]

    1. # bad
    2. scope :foo, where(:bar => 1)
    3. # good
    4. scope :foo, -> { where(:bar => 1) }