In my Rails app have a default scope that looks like this:
default_scope order: \'external_updated_at DESC\'
I have now upgraded to Rails 4
Should be only:
class Ticket < ActiveRecord::Base
default_scope -> { order(:external_updated_at) }
end
default_scope accept a block, lambda is necessary for scope(), because there are 2 parameters, name and block:
class Shirt < ActiveRecord::Base
scope :red, -> { where(color: 'red') }
end
This also worked for me:
default_scope { order('created_at DESC') }
This works for me in Rails 4
default_scope { order(external_updated_at: :desc) }
default_scope -> { order(created_at: :desc) }
Don't forget the ->
symbol
This worked from me (just for illustration with a where) because I came to this topic via the same problem.
default_scope { where(form: "WorkExperience") }
default_scope {
where(published: true)
}
Try This.