aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorAngel N. Sciortino <contact@angeliccomputing.com>2013-09-24 13:42:06 -0500
committerAngel N. Sciortino <contact@angeliccomputing.com>2013-09-24 13:42:06 -0500
commit8ae80447262020e3ff5eda2e5f5bf73bd432b300 (patch)
tree60329a342e5e9912193faed41e8a1123ccaededa /actionview
parentb1178aef3b44bd9e0153d2c4f8a2a2a590949999 (diff)
downloadrails-8ae80447262020e3ff5eda2e5f5bf73bd432b300.tar.gz
rails-8ae80447262020e3ff5eda2e5f5bf73bd432b300.tar.bz2
rails-8ae80447262020e3ff5eda2e5f5bf73bd432b300.zip
Use the given name in html_options for the hidden field in collection_check_boxes
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/helpers/tags/collection_check_boxes.rb3
-rw-r--r--actionview/test/template/form_collections_helper_test.rb7
2 files changed, 9 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb
index 52006d856b..9b77ebeb1b 100644
--- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb
+++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb
@@ -27,7 +27,8 @@ module ActionView
# Append a hidden field to make sure something will be sent back to the
# server if all check boxes are unchecked.
- hidden = @template_object.hidden_field_tag("#{tag_name}[]", "", :id => nil)
+ hidden_name = @html_options[:name] || "#{tag_name}[]"
+ hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil)
rendered_collection + hidden
end
diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb
index b56847396d..d28e4aeb48 100644
--- a/actionview/test/template/form_collections_helper_test.rb
+++ b/actionview/test/template/form_collections_helper_test.rb
@@ -179,6 +179,13 @@ class FormCollectionsHelperTest < ActionView::TestCase
assert_select "input[type=hidden][name='user[category_ids][]'][value=]", :count => 1
end
+ test 'collection check boxes generates a hidden field using the given :name in :html_options' do
+ collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
+ with_collection_check_boxes :user, :category_ids, collection, :id, :name, {}, {name: "user[other_category_ids][]"}
+
+ assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1
+ end
+
test 'collection check boxes accepts a collection and generate a serie of checkboxes with labels for label method' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name