声望系统得到upvoted项目
Reputation-system get upvoted items
我正在尝试遍历 post 模型并向用户显示已投票的 posted。
文档上的方式是这样的:
def vote
value = params[:type] == "Vote" ? 1 : 0
@post = Post.find(params[:id])
@post.add_or_update_evaluation(:votes, value, current_user)
redirect_to :back
end
def index
@posts = Post.where(current_user.id).find_with_reputation(:votes, value: 1.0).paginate(page: params[:page], per_page: 22)
end
<ul>
<% @posts.each do |post| %>
<li><span><%= link_to post.author.name, author_path(author.id)%></span></li>
<li><span><%= link_to post.title post_path(post.id) %></span></li>
<li><p><%= post.body %></p></li>
<li><%= post.created_at %></li>
</ul>
但 rails 正在吐出未知键:值。有人对此有任何建议吗?
谢谢
find_with_reputation 中的第二个参数是作用域,因此您可能是指:find_with_reputation(:votes, :all, {:conditions => ["votes = ?", value]})
或
find_with_reputation(:votes, :all, {:conditions => ["votes = ?", 1.0]})
我正在尝试遍历 post 模型并向用户显示已投票的 posted。 文档上的方式是这样的:
def vote
value = params[:type] == "Vote" ? 1 : 0
@post = Post.find(params[:id])
@post.add_or_update_evaluation(:votes, value, current_user)
redirect_to :back
end
def index
@posts = Post.where(current_user.id).find_with_reputation(:votes, value: 1.0).paginate(page: params[:page], per_page: 22)
end
<ul>
<% @posts.each do |post| %>
<li><span><%= link_to post.author.name, author_path(author.id)%></span></li>
<li><span><%= link_to post.title post_path(post.id) %></span></li>
<li><p><%= post.body %></p></li>
<li><%= post.created_at %></li>
</ul>
但 rails 正在吐出未知键:值。有人对此有任何建议吗? 谢谢
find_with_reputation 中的第二个参数是作用域,因此您可能是指:find_with_reputation(:votes, :all, {:conditions => ["votes = ?", value]})
或
find_with_reputation(:votes, :all, {:conditions => ["votes = ?", 1.0]})