Skip to content
Browse files

fixed for zero votes

  • Loading branch information...
1 parent e7ef9f0 commit f58e987f5d00b61f64f0cb998a1de9cea9f39c9b @joeellis committed
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/acts_as_voteable.rb
View
5 lib/acts_as_voteable.rb
@@ -94,7 +94,10 @@ def tally(*args)
# Use the explicit SQL statement throughout for Postgresql compatibility.
vote_count = "COUNT(#{Vote.table_name}.voteable_id)"
- t = self.where("#{Vote.table_name}.voteable_type = '#{self.name}'")
+ # Column commented out to support showing 0 votes for models. This line won't work as
+ # if there are no votes for a model, then it can't filter by this where clause, so the
+ # results come out as null, instead of just counting it as 0.
+ # t = self.where("#{Vote.table_name}.voteable_type = '#{self.name}'")
# We join so that you can order by columns on the voteable model.
t = t.joins("LEFT OUTER JOIN #{Vote.table_name} ON #{self.table_name}.#{self.primary_key} = #{Vote.table_name}.voteable_id")

0 comments on commit f58e987

Please sign in to comment.
Something went wrong with that request. Please try again.