我正在尝试将 Upvote 函数与acts_as_votable
gem 结合使用。我遇到的问题是,当我将鼠标悬停在 Upvote 链接上时,我可以看到comment.id
URL 预览没有给出,然后当我单击 Upvote 时,错误消息告诉我:
Couldn't find Comment with 'id'=#
<Comment::ActiveRecord_Relation:0x007f813b169658>
我视图中的评论循环如下所示:
<div class="box">
<% @comment.each do |w| %>
<tr>
<td><b><%= w.title %></b></td><br>
<td><%= w.location %></td><br>
<td><%= w.body %></td><br>
<%= link_to "upvote", like_comment_path(@comment), method: :put
%><br>
</tr>
<% end %>
</div>
还有我的CommentsController:
def upvote
@comment = Comment.find(params[:id])
@comment.upvote_by current_user
redirect_to comments_path
end
还有我的配置/路线:
resources :comments do
member do
put "like", to: "comments#upvote"
put "dislike", to: "comments#downvote"
end
end
这感觉应该是非常简单的事情,但我就是不知道为什么没有给出 id,所以非常感谢帮助:-)