Ruby on Rails: how do I sort with two columns using ActiveRecord?

前端 未结 7 1080
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 23:39

I want to sort by two columns, one is a DateTime (updated_at), and the other is a Decimal (Price)

I would like to be able to sort first by updated_at, t

7条回答
  •  情深已故
    2020-12-01 00:34

    Thing.find(:all, :order => "updated_at desc, price asc")
    

    will do the trick.

    Update:

    Thing.all.order("updated_at DESC, price ASC")
    

    is the Rails 3 way to go. (Thanks @cpursley)

提交回复
热议问题