How to create a delete link for a related object in Ruby on Rails?

后端 未结 3 818
一向
一向 2020-12-24 04:59

So let\'s say I have Posts and Comments and the url for show is /posts/1/comments/1. I want to create a link to delete that comment in the comments controller d

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 05:33

    Since some time ago, the confirm option has to be included in a data hash, otherwise it will be silently ignored:

    <%= link_to 'Destroy',  post_comment_path(@post, comment),
        data: { confirm: 'Are you sure?' }, method: :delete %>
    

提交回复
热议问题