RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: arrog
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
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