Adding a delete link for nested attributes

后端 未结 3 767
情话喂你
情话喂你 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:02

    The variable you're using l isn't correct. When you yield from a fields_for block the block object is an instance of FormBuilder not an instance of the object itself. What url do you want the link to point to? Is it Answers#destroy? What id do you want to send to this action for it to identify what to destroy? A link_to isn't a form element. It's just a helper for an anchor tag. You need a url, not a form builder to build that link.

    Is this going to be a list of answer forms? One for each answer? If so, you might want to loop through them instead of just using fields_for.

    Hopefully this helps you get on the right track.

提交回复
热议问题