RAILS 4: 'delete' 按钮有问题

RAILS 4: problems with 'delete' button

我有一个嵌套资源,评论是这样的....

resources :microposts do

   member do
     get :upvote, :undo_upvote
   end

   member do
     get :follow, :unfollow
   end

   resources :responses do
     member do
       get :upvote, :undo_upvote
     end
     resources :comments
  end
end

我在评论索引页上有一个删除按钮....

 <div class = "Comment" id="comment-<%= comment.id %>">
     <%= link_to comment_avatar_for(comment.user), comment.user %>
     <span class="Commentator">
       <%= comment.user.full_name %>
     </span>
     <span class="content">
       <%= comment.body %>
     </span>
     <span class="timestamp">
     Posted <%= time_ago_in_words(comment.created_at) %> ago.
     </span>
     <span class="timestamp">
       <% if current_user?(comment.user) %>
       <%= link_to "delete", comment, method: :delete, data: { confirm: "You sure?" }, :class => "btn btn-default btn-xs delete" %>
      <% end %>
     </span>
</div>

加载页面时出现此错误

 undefined method `comment_path' for #<#  <Class:0x007f8936876e70>:0x007f8931857020>

我不确定为什么这不起作用 - 毕竟我有 'comment' 的正确实例。如果有人能指出我正确的方向,我将不胜感激。

Rails 做出假设。

因为你有一个 Comment 的实例,所以它假设你将使用 comment_path,但你没有根据你的路线使用它,所以你需要设置正确的路径:

<%= link_to "delete", micropost_response_comment_path(@micropost, @response, comment), method: :delete, data: { confirm: "You sure?" }, :class => "btn btn-default btn-xs delete" %>

我可能走错了路,但希望你明白了。