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
defself.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
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 theby_votes
class method to solve this. I also had to addgroup
to the query to get more than one haiku. WithoutSUM()
andgroup
I got duplicate haikus.