这是我的路线配置文件中的一行:
DELETE /posts/:post_id/comments/:id(.:format) posts/comments#destroy
我想删除一个注释,但语法不正确。这是我尝试过的:
<% if current_user == comment.user %>
<span class="edit-delete-line"><p><small><%= link_to "Delete", post_comments_path([@commentable, comment]), method: :delete, data: { confirm: "Are you sure?" } %> </span>
</small></p>
<% end %>
这给了我一个路由错误。我也尝试过:
<% if current_user == comment.user %>
<span class="edit-delete-line"><p><small><%= link_to "Delete", post_comments_path(params([:post_id], [:comment_id])), method: :delete, data: { confirm: "Are you sure?" } %> </span>
</small></p>
<% end %>
这次我收到“参数数量错误”错误。我知道这应该很简单,对吧???
您正在尝试删除单个注释,因此需要使用post_comment_path(@commentable, comment)
而不是复数post_comments_path
来指向index
。如果您将控制器设置为也接受未嵌套的资源(只是/comments/:id
),则可以直接使用comment_path
。
查看Rails路由指南以了解更多详细信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句