Created
May 16, 2019 13:23
-
-
Save wellington1993/01b84c5d5abf1f3ab50d0eb98282ab7e to your computer and use it in GitHub Desktop.
Default Scope Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default_scope | |
This works for Rails 4+: | |
class Book < ActiveRecord::Base | |
default_scope { order(created_at: :desc) } | |
end | |
For Rails 2.3, 3, you need this instead: | |
default_scope order('created_at DESC') | |
For Rails 2.x: | |
default_scope :order => 'created_at DESC' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment