Just came across a difference in the way rails 2 handles radio buttons, compared with rails 1, and I don't think I've seen it documented anywhere.
If you've got something like this;
<% form_for(@hello) do |f| %>Then, if you click on the "True" radio button, and submit the form, you get;
<p> <%= f.radio_button :foo, true %>True </p>
<p> <%= f.radio_button :foo, false %>False </p>
<p> <%= f.submit "Create" %> </p>
<% end %>
"hello"=>{"foo"=>"true"}...submitted to your controller. All fine.
Now, click on the "False" button and submit, and you get;
"hello"=>{"foo"=>"on"}Not quite so good. This can really mess you up if your controller method has something like;
if params[:foo] == "false"Do the same thing in Rails 1.2.6 and you get;
... do something cool
"hello"=>{"foo"=>"true"}and
"hello"=>{"foo"=>"false"}The moral of the story? Do this instead;
<% form_for(@hello) do |f| %>i.e. Use string values, not logical values, in the view file. This works fine in either version.
<p> <%= f.radio_button :foo, "true" %>True </p>
<p> <%= f.radio_button :foo, "false" %>False </p>
<p> <%= f.submit "Create" %> </p>
<% end %>
|