Rails没有路由匹配[DELETE]

时间:2017-11-25 20:11:46

标签: ruby-on-rails database oop

尝试删除回复

 <% @comment.replies.each do |reply| %>
 <td><%= link_to 'Destroy', comment_replies_path(reply), method: :delete, data: { confirm: 'Are you sure?' }%></td>

我收到以下错误

No route matches [DELETE] "/comments/66/replies"

rake routes

comment_reply_path  
          DELETE    /comments/:comment_id/replies/:id(.:format)   replies#destroy

我此时的网址是

http://localhost:3000/comments/66/replies

的routes.rb

resources :comments do
   resources :replies
end

1 个答案:

答案 0 :(得分:0)

您的路线显示comment_reply_path并且您正在使用comment_replies_path

您需要更新代码才能使用正确的路径助手

<%= link_to 'Destroy', comment_reply_path(reply), method: :delete, data: { confirm: 'Are you sure?' }%>