Skip to content
This repository
Browse code

Allow radio buttons to work with booleans.

[#2937 state:committed]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit e972acc0d7b63e5ce15bed69f41214fe741a7c9c 1 parent d0bdff0
José Valim authored July 24, 2009 jeremy committed August 09, 2009
4  actionpack/lib/action_view/helpers/form_helper.rb
@@ -861,8 +861,8 @@ def radio_button_checked?(value, checked_value)
861 861
 
862 862
       private
863 863
         def add_default_name_and_id_for_value(tag_value, options)
864  
-          if tag_value
865  
-            pretty_tag_value    = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
  864
+          unless tag_value.nil?
  865
+            pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
866 866
             specified_id = options["id"]
867 867
             add_default_name_and_id(options)
868 868
             options["id"] += "_#{pretty_tag_value}" unless specified_id
10  actionpack/test/template/form_helper_test.rb
@@ -311,6 +311,16 @@ def test_radio_button_respects_passed_in_id
311 311
     )
312 312
   end
313 313
 
  314
+  def test_radio_button_with_booleans
  315
+    assert_dom_equal('<input id="post_secret_true" name="post[secret]" type="radio" value="true" />',
  316
+      radio_button("post", "secret", true)
  317
+    )
  318
+
  319
+    assert_dom_equal('<input id="post_secret_false" name="post[secret]" type="radio" value="false" />',
  320
+      radio_button("post", "secret", false)
  321
+    )
  322
+  end
  323
+
314 324
   def test_text_area
315 325
     assert_dom_equal(
316 326
       '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',

0 notes on commit e972acc

Please sign in to comment.
Something went wrong with that request. Please try again.