acts_as_votable无路由匹配错误导轨5

时间:2017-01-23 19:45:05

标签: ruby-on-rails rubygems nomethoderror acts-as-votable

我正在尝试将acts_as_votable添加到我的rails 5 app上发布评论。 宝石安装得很好,我添加了两个迁移(ActsAsVotable和AddCachedLikesToVotes)和我添加的CommentsController

def like
  @post = Post.find(params[:post_id])
  @comment = @post.comments.find(params[:id])
end

def vote
  if !current_user.lked? @comment
    @comment.liked_by current_user
  elsif current_user.liked? @comment
    @comment.unliked_by current_user
  end
end

然后我将此添加到我的评论部分视图中:

<%= link_to like_post_comment_path(@post, comment), class: "like-btn", method: :put, remote: :true do %>

我的错误是针对以上行。它说的是:

没有路由匹配{:action =&gt;“vote”,:controller =&gt;“comments”,:id =&gt; nil,:post_id =&gt;“1”}缺少必需的键:[: ID]

like_post_comment_path是正确的,我在(@post, comment)(@comment.post_id, comment)(@post, @comment)等之间尝试了不同的变体,但没有任何效果!

1 个答案:

答案 0 :(得分:0)

试试这个

<%= link_to like_post_comment_path(comment, poste_id: @poste.id), class: "like-btn", method: :put, remote: :true do %>