Rails 4 default scope

前端 未结 8 2099
萌比男神i
萌比男神i 2020-12-04 15:21

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

相关标签:
8条回答
  • 2020-12-04 16:09

    You can also use the lambda keyword. This is useful for multiline blocks.

    default_scope lambda {
      order(external_updated_at: :desc)
    }
    

    which is equivalent to

    default_scope -> { order(external_updated_at: :desc) }
    

    and

    default_scope { order(external_updated_at: :desc) }
    
    0 讨论(0)
  • 2020-12-04 16:15

    This is what worked for me:

    default_scope  { order(:created_at => :desc) }
    
    0 讨论(0)
提交回复
热议问题