Topic: Sorting different kinds of models in an array

Hey is this the best way to do this? I am going to add something like this to my controller so that I can have a combined thread of different kinds of activity (comments, posts, photos, whatevs). All the different models do have a created_at column tho and that's how I figure I'd sort them.

So here is how I would do it. Am I going about it wrong? Thanks.

posts = Post.find(:all)
comments = Comment.find(:all)
pc = (posts + comments).sort_by { |a| a[:created_at] }.reverse!

Also, how would I go about then limiting the number of objects to display in 'pc' or applying different conditions to 'pc'? Thanks!

Last edited by alright.dylan (2007-07-20 08:47:30)