check_box broken in Rails 2.0.2?
February 26th, 2008
I was having an awful time submitting a form with a check_box. No matter what I did, it would only return “0” or “false”, never “1” or “true”, no matter how hard I mashed the mouse button on the check box.
<%= check_box :fund, :tax_deductible %> <%= f.label :tax_deductible %>
I finally tried moving to edge Rails (from Rails 2.0.2), and the problem went away. Anyone else experience this?
2 Responses to “check_box broken in Rails 2.0.2?”
Sorry, comments are closed for this article.
February 27th, 2008 at 12:17 PM
Hey Ryan,
What HTML is the check_box generating? Maybe that would help.
Jeff
February 27th, 2008 at 12:27 PM
Hi Jeff,
The HTML output was just as you would expect:
But when the form was submitted, the params hash looked something like this:
... even if the box was checked – it would always return “0” or “false” or whatever I put as the false value, no matter what.
For some reason, upgrading to edge rails fixed the problem. I was picking round in the active_support source a bit, and they did some refactoring to the form helpers, so I’m assuming that it is a bug in Rails 2.0.2.