Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Gerald M's Profile

GitHub User: factor4

Site: http://www.factor4.at

Comments by Gerald M

Avatar

Hi binaryx,

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

Avatar

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.

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