Given the three models “message”, “profile” and “comment” i want to merge them into one list, ordered by their common attribute “created_at”. I want to accomplish something like the project overview in Basecamp - see 3) here: http://basecamphq.com/tour#overview
+1
A:
Try something like this:
messages = Message.all
profiles = Profile.all
comments = Comment.all
list = [messages, profiles, comments].flatten
sorted_list = list.sort_by { |item| item.created_at.strftime('%m/%d/%y') }
John Glass
2010-05-21 23:54:09
Works perfect, thanks!
Labuschin
2010-05-22 06:54:49