How do you order by a custom model method that has no attribute in SQL?

前端 未结 6 1110
生来不讨喜
生来不讨喜 2021-02-02 08:11

Previously I ordered my posts as this:

@posts = Post.find(:all, :order => \"created_at DESC\")

But now I want to replace created_at

6条回答
  •  醉梦人生
    2021-02-02 08:56

    in rails 3 we can do this as: Post.order("custom_method DESC")
    When upgrading app from rails2 to rails3

提交回复
热议问题