Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check_box value can be not only an object of Array class

there is a chance that `value` is a Set or an object that reponses to `include?` method so let's handle this case
  • Loading branch information...
commit 3ee6bcfc3d3e7be0dd3b76ac929500aaf031f8f9 1 parent bfc6c17
@nashby nashby authored
View
8 actionpack/lib/action_view/helpers/tags/check_box.rb
@@ -46,10 +46,12 @@ def checked?(value)
false
when String
value == @checked_value
- when Array
- value.include?(@checked_value)
else
- value.to_i == @checked_value.to_i
+ if value.respond_to?(:include?)
+ value.include?(@checked_value)
+ else
+ value.to_i == @checked_value.to_i
+ end
end
end
View
6 actionpack/test/template/form_helper_test.rb
@@ -400,6 +400,12 @@ def test_check_box_checked_if_object_value_includes_checked_value
'<input name="post[secret]" type="hidden" value="0" /><input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
check_box("post", "secret")
)
+
+ @post.secret = Set.new(['1'])
+ assert_dom_equal(
+ '<input name="post[secret]" type="hidden" value="0" /><input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
+ check_box("post", "secret")
+ )
end
def test_check_box_with_include_hidden_false
Please sign in to comment.
Something went wrong with that request. Please try again.