Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 显示在post acts_as_votable上投票的用户_Ruby On Rails - Fatal编程技术网

Ruby on rails 显示在post acts_as_votable上投票的用户

Ruby on rails 显示在post acts_as_votable上投票的用户,ruby-on-rails,Ruby On Rails,我正在使用acts_as_votable gem,并已经实现了它,以便用户可以对post模型进行投票。我想做的是,当我显示帖子时,我想列出哪些用户投了赞成票。我当前通过以下方式显示分数: <%= post.cached_votes_score %> Iv添加了它,这样用户就是投票人,帖子是可投票的 我还添加了缓存迁移: class AddCachedVotesToPosts < ActiveRecord::Migration def self.up add_column

我正在使用acts_as_votable gem,并已经实现了它,以便用户可以对post模型进行投票。我想做的是,当我显示帖子时,我想列出哪些用户投了赞成票。我当前通过以下方式显示分数:

<%= post.cached_votes_score %> 
Iv添加了它,这样用户就是投票人,帖子是可投票的

我还添加了缓存迁移:

class AddCachedVotesToPosts < ActiveRecord::Migration
 def self.up
 add_column :posts, :cached_votes_total, :integer, :default => 0
 add_column :posts, :cached_votes_score, :integer, :default => 0
 add_column :posts, :cached_votes_up, :integer, :default => 0
 add_column :posts, :cached_votes_down, :integer, :default => 0
 add_column :posts, :cached_weighted_score, :integer, :default => 0
 add_column :posts, :cached_weighted_total, :integer, :default => 0
 add_column :posts, :cached_weighted_average, :float, :default => 0.0
 add_index  :posts, :cached_votes_total
 add_index  :posts, :cached_votes_score
 add_index  :posts, :cached_votes_up
 add_index  :posts, :cached_votes_down
 add_index  :posts, :cached_weighted_score
 add_index  :posts, :cached_weighted_total
 add_index  :posts, :cached_weighted_average
end

def self.down
 remove_column :posts, :cached_votes_total
 remove_column :posts, :cached_votes_score
 remove_column :posts, :cached_votes_up
 remove_column :posts, :cached_votes_down
 remove_column :posts, :cached_weighted_score
 remove_column :posts, :cached_weighted_total
 remove_column :posts, :cached_weighted_average
end
end
类AddCachedVotesToPosts0 添加列:posts,:cached\u voces\u score,:integer,:default=>0 添加列:posts、:cached\u vows\u up、:integer、:default=>0 添加列:posts、:cached\u vows\u down、:integer、:default=>0 添加列:posts,:缓存的\u加权\u分数,:integer,:default=>0 添加列:posts,:cached,:weighted,:integer,:default=>0 添加列:posts,:cached,:weighted,:float,:default=>0.0 添加索引:帖子、缓存的投票总数 添加索引:帖子、缓存的投票 添加索引:帖子、缓存的投票 添加索引:posts,:cached\u投票\u down 添加索引:帖子,:缓存的\u加权\u分数 添加索引:posts,:cached\u加权\u总计 添加索引:帖子,:缓存的\u加权\u平均值 结束 def自动关闭 删除\u列:帖子,:缓存的\u投票\u总数 删除\u列:帖子,:缓存的\u投票\u分数 删除列:帖子、缓存的投票 删除列:发布,:缓存的\u投票\u关闭 删除列:帖子,:缓存的\u加权\u分数 删除\u列:帖子,:缓存\u加权\u总计 删除列:帖子,:缓存的\u加权\u平均值 结束 结束 任何帮助都将不胜感激。如果你想让我在上面添加任何代码,也一定要让我知道


编辑这里是gem的链接

你能试试下面的代码来获取用户名吗

@post.vote_by 

您可以使用下面的代码获取该帖子的所有投票者id列表

 @post.votes_for_ids

投票者投稿有用吗?@JoeKennedy恐怕不行。我得到未定义的方法。它返回false。就像照片上的假照片一样。嘿@冰柱让我得到了身份证,这是伟大的一步。在我的用户模型上,我有一个图像字段。你知道我怎样才能用这些ID打印出来吗?请尝试使用下面的代码片段,它将为用户提供可用于获取图像字段数据的对象@post.voaters\u for.votersperfect获得:)非常感谢。对于感兴趣的人,这里是代码
 @post.votes_for_ids