title: ActiveRecord and SELECT AS SQL statements
body: <p>I am developing in Rails an app where I would like to rank a list of users based on their current points. The table looks like this: user_id:string, points:integer.
  Since I can't figure out how to do this "The Rails Way", I've written the following SQL code:</p>
  
  <pre><code>self.find_by_sql ['SELECT t1.user_id, t1.points, COUNT(t2.points) as user_rank FROM registrations as t1, registrations as t2 WHERE t1.points &lt;= t2.points OR (t1.points = t2.points AND t1.user_id = t2.user_id) GROUP BY t1.user_id, t1.points ORDER BY t1.points DESC, t1.user_id DESC']
  </code></pre>
  
  <p>The thing is this: the only way to access the aliased column "user_rank" is by doing ranking[0].user_rank, which brinks me lots of headaches if I wanted to easily display the resulting table.</p>
  
  <p>Is there a better option?</p>