From defb751681640e11f2187439acdaaa12ca9b805f Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Fri, 6 Jan 2012 17:14:49 +0100 Subject: don't set the hidden checkbox value if it's nil --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- actionpack/test/template/form_helper_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index fa2ebf881c..294dee8e2a 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1092,7 +1092,7 @@ module ActionView else add_default_name_and_id(options) end - hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) + hidden = unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) : "" checkbox = tag("input", options) (hidden + checkbox).html_safe end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 670cecfb9e..6e26fe752e 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -373,6 +373,14 @@ class FormHelperTest < ActionView::TestCase ) end + def test_check_box_with_nil_unchecked_value + @post.secret = "on" + assert_dom_equal( + '', + check_box("post", "secret", {}, "on", nil) + ) + end + def test_check_box_with_multiple_behavior @post.comment_ids = [2,3] assert_dom_equal( -- cgit v1.2.3