Adding a delete link for nested attributes

后端 未结 3 777
情话喂你
情话喂你 2021-01-18 04:46

I have nested attributes in my show.erb and I create a blank nested attribute and show a grid of items with the blank at the bottom like so.

<%= form_for          


        
3条回答
  •  不要未来只要你来
    2021-01-18 05:16

    Why do you want to use a link? You can also use the destroy functionality in the nested attributes.

    All you need to do is to add :allow_destroy => true in your accepts_nested_attributes definition and add

    <%= l.check_box '_destroy' %>
    

    to each record. That way it removes all the nested records with the check-box checked when saving the record.

提交回复
热议问题