【问题标题】:Listing users that voted on post using acts_as_votable列出使用acts_as_votable对帖子投票的用户
【发布时间】:2015-03-04 23:19:46
【问题描述】:

我正在尝试显示使用acts_as_votable gem 为帖子点赞的用户的图像,就像this question 一样。问题是适用于该问题的答案在我的情况下不起作用。

我这样显示赞成票数:

<%= @post.cached_votes_total %> 

我已将“acts_as_votable”和“acts_as_voter”添加到帖子和用户模型中。

控制器:

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

上述问题中接受的答案是这样的:

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

但是,这给了我一个“未定义的方法 `votes_for'”错误。

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

这没有错误,但我无法访问用户的图像。

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    好的,我玩了一会儿就明白了。

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

    【讨论】:

      猜你喜欢
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 2014-07-16
      相关资源
      最近更新 更多