1
votes

Within my rails app, i'm using the acts_as_votable gem to allow voting on my Post model.

I'm trying to retrieve a list of all posts that the current user has not upvoted or downvoted. How do I do this?

This gives me the list of ids of all users that have voted on a particular post. Do I need to run this method on all posts and scan against the current user and map out the results, or is there a more efficient way to do this?

@post.votes_for_ids
1

1 Answers

2
votes

User has the following methods available, see the github doc

@user.find_voted_items

@user.find_up_voted_items
@user.find_liked_items

@user.find_down_voted_items
@user.find_disliked_items

So using these methods you could

@not_voted_on = Post.where.not(id: @user.find_voted_items.map(&:id))