Jaqx
Jaqx

Reputation: 826

find user vote count for specific voteable (thumbs_up gem)

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

Answers (1)

Jaqx
Jaqx

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

Related Questions