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

前端 未结 6 1138
生来不讨喜
生来不讨喜 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条回答
  •  旧时难觅i
    2021-02-02 08:53

    Just to expand on @Robbie's answer

    Post.all.sort_by {|post| post.custom_method }.reverse
    

提交回复
热议问题