Question

The Rails guide says I can use this checkbox to let users delete a nested attribute. It has a typo, doesn't seem to use the builder addresses_form, and creates an error when I try to copy it in my app.

Any idea what the correct syntax for a checkbox would be here?

The seemingly incorrect guide is here - Section 9.4 Removing Objects - http://guides.rubyonrails.org/form_helpers.html#removing-objects

<%= form_for @person do |f| %>
  Addresses:
  <ul>
    <%= f.fields_for :addresses do |addresses_form| %>
      <li>
        <%= check_box :_destroy%> # This seems wrong and gives error
        <%= addresses_form.label :kind %>
        <%= addresses_form.text_field :kind %>
        ...
      </li>
    <% end %>
  </ul>
<% end %>

Produces error:

wrong number of arguments (1 for 2..5)

Was it helpful?

Solution

You need to change check_box :_destroy to addresses_form.check_box :_destroy.

There are two methods called check_box - one is called on a form object and can be called with a single argument, the other is a view helper and requires at least two arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top