Reputation: 160
there I am working with rails 2. I am having manually created array having different values of active records, I want to sort the array by created_at, but not getting any clue, I am stuck. Please help
Here is my code:
@player_ranking_details[:qb].each do |nfd|
@new_nfd << nfd.player.news_breakers.last
end
and output :
[#<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">...]
Is there any way to sort my records in array ny created_at in desc order.
Upvotes: 0
Views: 45
Reputation: 960
you can sort an array any time with attributes, here @new_nfd.sort_by { |i| i.created_at }
For descending order, reverse
the above result.
Upvotes: 1