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?”

  1. Jeff Berg Says:

    Hey Ryan,

    What HTML is the check_box generating? Maybe that would help.

    Jeff

  2. Ryan Says:

    Hi Jeff,

    The HTML output was just as you would expect:

    
      <input checked="checked" id="fund_tax_deductible" name="fund[tax_deductible]" type="checkbox" value="1" />
      <input name="fund[tax_deductible]" type="hidden" value="0" />
    

    But when the form was submitted, the params hash looked something like this:

    
      "fund"=>{"name"=>"General Support", "tax_deductible"=>"0"}
    

    ... 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.

Sorry, comments are closed for this article.