Search code examples
ruby-on-rails-3form-helpers

Having an issue with check_box and boolean attribute


I'm using a checkbox in the edit action, and when I go into the form and "check" the box, everything works fine. But then when I go back and try to "uncheck the box" it doesn't seem to save.

Here's my code for the form:

<%= f.label :winning, "Did this Proposal Win?", class: "input-title" %>
<%= f.check_box :winning, {}, true, false %>

Solution

  • Why are you providing this set of extra parameters? Do just this:

    <%= f.check_box :winning %>
    

    Eventually - try to use 1 and 0, not true and false.