Adding additional sorting attributes to array of records...then sorting!

Posted by keruilin on Stack Overflow See other posts from Stack Overflow or by keruilin
Published on 2010-06-17T02:48:25Z Indexed on 2010/06/17 2:52 UTC
Read the original article Hit count: 185

Filed under:
|
|

Let's say I run an ActiveRecord query and it returns 3 results, with a bunch of attributes.

I want to add 3 attributes to each record in the Array so I can do sorting at a code-level. These 3 include: num_comments, num_views, last_view.

  1. How do I add these attributes?
  2. How do I then sort the records, in order of precendence, by num_comments AND by num_views AND by last_view?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about sorting