按 created_at 对手动创建的活动记录数组进行排序

Sort the manualy created array of active records by created_at

我正在使用 rails 2. 我手动创建了具有不同活动记录值的数组,我想按 created_at 对数组进行排序,但没有得到任何线索,我我卡住了。请帮忙

这是我的代码:

@player_ranking_details[:qb].each do |nfd|
  @new_nfd << nfd.player.news_breakers.last
end

并输出:

[#<NewsBreaker id: 4562, player_id: 981, title: "Newsfeed for week 6", source: "http://pyromaniac.com", active: true, publish_time: "2017-05-25 06:05:00", feature: false, sticky: false, created_at: "2017-05-25 06:06:38", updated_at: "2017-08-09 12:53:41">, #<NewsBreaker id: 3361, player_id: 187, , title: "Troy Polamalu ruled out for Week 15", source: "http://twitter.com/jimwexell/status/6701947444", active: true, publish_time: "2009-12-15 18:00:00", feature: true, sticky: false, created_at: "2009-12-15 20:33:46", updated_at: "2009-12-15 20:33:46">...]

有什么方法可以按降序对数组 ny created_at 中的记录进行排序。

您可以随时使用属性对数组进行排序,这里 @new_nfd.sort_by { |i| i.created_at }

对于降序,reverse上面的结果。