1
votes

I'm trying to display the images of the users who've upvoted a post using the acts_as_votable gem, exactly like this question. The problem is the answer that worked for that question is not working in my case.

I display the upvotes count like this:

<%= @post.cached_votes_total %> 

I've added 'acts_as_votable' and 'acts_as_voter' into the post and user models.

The controller:

def upvote
  @post = Post.find params[:id]
  @post.liked_by current_user
end

The accepted answer in the above question is this:

<% @post.votes_for.voters.each do |p| %> 
  <%= image_tag(p.image) %> 
<% end %>

However this gives me an 'undefined method `votes_for' ' error.

<% @post.votes.each do |user| %>
  <%= user %>
<% end %>

This gives no error but I can't access the user's image.

1

1 Answers

1
votes

Ok, I got it by playing around a bit more.

<% @post.votes.by_type(User).voters.each do |user| %>