Skip to content

Commit

Permalink
Merge pull request #8002 from nashby/checkbox-include
Browse files Browse the repository at this point in the history
check_box value can be not only an object of Array class
  • Loading branch information
rafaelfranca committed Oct 20, 2012
2 parents 4ed1563 + 3ee6bcf commit 3be9e8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions actionpack/lib/action_view/helpers/tags/check_box.rb
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 3be9e8a

Please sign in to comment.