Sort array returned by ActiveRecord by date (or any other column)

前端 未结 5 1240
南方客
南方客 2020-12-22 23:34

How can I sort an array returned by an ActiveRecord query by a created_at date column?

This occurs once the query has been executed.

Please don

5条回答
  •  既然无缘
    2020-12-23 00:00

    Ruby includes support for sorting out of the box.

    sorted = @records.sort_by &:created_at
    

    However, this doesn't appear to have much to do with display and probably belongs in the controller.

提交回复
热议问题