通过ActiveRecord的返回日期分类数组(或任何其它列) [英] Sort array returned by ActiveRecord by date (or any other column)
本文介绍了通过ActiveRecord的返回日期分类数组(或任何其它列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何排序由 created_at
日期列由ActiveRecord的查询返回数组?
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't tell me to do it in the query because I need this to happen in the view.
推荐答案
红宝石包括整理出框的支持。
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.
这篇关于通过ActiveRecord的返回日期分类数组(或任何其它列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文