Reputation: 380
how i get to save unchecked chekboxes on rails?
I researched some links, but i as unable to find a working solution for me.
i got:
<% @book.each do |book| %>
<div>
<%= check_box_tag "orb[book_ids][]", book.id, @orb.books.include?(book) %>
<%= book.nome %>
</div>
<% end %>
when i uncheck all checkboxes, it didn't save :P
I tried to use a hidden field, but it gave me the error "there no book with id=0"
Upvotes: 0
Views: 38
Reputation: 3732
Add this:
<%= hidden_field_tag 'orb[book_ids][]', '' %>
You form should looks like:
<% @book.each do |book| %>
<div>
<%= check_box_tag "orb[book_ids][]", book.id, @orb.books.include?(book) %>
<%= book.nome %>
</div>
<% end %>
<%= hidden_field_tag 'orb[book_ids][]', '' %>
Upvotes: 3