RailsCasts Pro episodes are now free!

Learn more or hide this

Gerald M's Profile

GitHub User: factor4

Site: http://www.factor4.at

Comments by Gerald M


Hi binaryx,

try the reputation-system-from-scratch. I got this to work with will_paginate.


Hi Ryan,

I had a problem with your reputation-system-from-scratch, that all haikus with more than one vote were ordered as they had only one vote. I added the SUM() function to the by_votes class method to solve this. I also had to add group to the query to get more than one haiku. Without SUM() and group I got duplicate haikus.

def self.by_votes
  select('haikus.*, coalesce(SUM(value), 0) as votes').
  joins('left join haiku_votes on haiku_id=haikus.id').
  order('votes desc')