Reputation: 826
I'm using this gem and I would like to get a user's vote count for posts
https://github.com/bouchard/thumbs_up/blob/master/lib/acts_as_voter.rb
However when I do
@user.vote_count
It returns the user's vote count for everything I have comments, photos, etc. I want to do something like @user.vote_count.where('voteable_type = Micropost') but obviously that doesn't make any sense
Upvotes: 2
Views: 226
Reputation: 826
Vote.find_by_sql("SELECT COUNT(*) FROM votes WHERE votes.voter_id = #{@user.id} AND votes.voter_type = 'User' AND votes.voteable_type = 'Micropost'").count
probably not the best to use SQL but it works
Upvotes: 1