Permalink
Browse files

Allow radio buttons to work with booleans.

[#2937 state:committed]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent d0bdff0 commit e972acc0d7b63e5ce15bed69f41214fe741a7c9c @josevalim josevalim committed with jeremy Jul 23, 2009
Showing with 12 additions and 2 deletions.
  1. +2 −2 actionpack/lib/action_view/helpers/form_helper.rb
  2. +10 −0 actionpack/test/template/form_helper_test.rb
@@ -861,8 +861,8 @@ def radio_button_checked?(value, checked_value)
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
@@ -311,6 +311,16 @@ def test_radio_button_respects_passed_in_id
)
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>',

0 comments on commit e972acc

Please sign in to comment.