diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-24 00:05:57 +0200 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 18:02:07 +0100 |
commit | c34d6279a06c80c51eefc3d345c24eab9a1e44fe (patch) | |
tree | 278cbabb92ed1fa917c294f396404ecc0acf33bf | |
parent | 1191e3ffaf7ced4155eb6c2b1661e27d7851ca9a (diff) | |
download | rails-c34d6279a06c80c51eefc3d345c24eab9a1e44fe.tar.gz rails-c34d6279a06c80c51eefc3d345c24eab9a1e44fe.tar.bz2 rails-c34d6279a06c80c51eefc3d345c24eab9a1e44fe.zip |
Allow radio buttons to work with booleans.
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 4 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 6e2990e084..bde600f6ed 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -872,8 +872,8 @@ module ActionView private def add_default_name_and_id_for_value(tag_value, options) - if tag_value - pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase + unless tag_value.nil? + pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase specified_id = options["id"] add_default_name_and_id(options) options["id"] += "_#{pretty_tag_value}" unless specified_id diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 99160dd8b1..2b1d80b1bf 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -307,6 +307,16 @@ class FormHelperTest < ActionView::TestCase ) end + def test_radio_button_with_booleans + assert_dom_equal('<input id="post_secret_true" name="post[secret]" type="radio" value="true" />', + radio_button("post", "secret", true) + ) + + assert_dom_equal('<input id="post_secret_false" name="post[secret]" type="radio" value="false" />', + radio_button("post", "secret", false) + ) + end + def test_text_area assert_dom_equal( '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>', |