RailsCasts Pro episodes are now free!

Learn more or hide this

arrog's Profile

GitHub User: arrog

Comments by

Avatar

As said above, in your model

def count_positive
evaluations.where( target_type: self.class, target_id: self.id, value: 1.0 ).count
end

def count_negative
evaluations.where( target_type: self.class, target_id: self.id, value: -1.0 ).count
end

then you can sum up both in your view

or

def count_total
evaluations.where( target_type: self.class, target_id: self.id, value: 1.0 ).count + evaluations.where( target_type: self.class, target_id: self.id, value: -1.0 ).count
end