Techmago
Techmago

Reputation: 380

How to save uncheked check boxes

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

Answers (1)

Oleg Haidul
Oleg Haidul

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

Related Questions