aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view
diff options
context:
space:
mode:
authorVasiliy Ermolovich <younash@gmail.com>2014-04-13 21:58:42 +0300
committerVasiliy Ermolovich <younash@gmail.com>2014-04-14 17:13:43 +0300
commit3964bbc490bdd858b431862bdefa58f477cb2028 (patch)
tree25f3ce6c7f947642e587cd5d68d408548ff3f8fd /actionview/lib/action_view
parent0bccde963c0b3e2ad65b2bdac9d144f40854ec90 (diff)
downloadrails-3964bbc490bdd858b431862bdefa58f477cb2028.tar.gz
rails-3964bbc490bdd858b431862bdefa58f477cb2028.tar.bz2
rails-3964bbc490bdd858b431862bdefa58f477cb2028.zip
`collection_check_boxes` respects `:index` option for the hidden filed name.
closes #14147
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r--actionview/lib/action_view/helpers/tags/collection_check_boxes.rb17
1 files changed, 13 insertions, 4 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 8b28e4fc33..6242a2a085 100644
--- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb
+++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb
@@ -28,10 +28,7 @@ module ActionView
# Append a hidden field to make sure something will be sent back to the
# server if all check boxes are unchecked.
if @options.fetch(:include_hidden, true)
- hidden_name = @html_options[:name] || "#{tag_name}[]"
- hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil)
-
- rendered_collection + hidden
+ rendered_collection + hidden_field
else
rendered_collection
end
@@ -42,6 +39,18 @@ module ActionView
def render_component(builder)
builder.check_box + builder.label
end
+
+ def hidden_field
+ hidden_name = @html_options[:name]
+
+ hidden_name ||= if @options.has_key?(:index)
+ "#{tag_name_with_index(@options[:index])}[]"
+ else
+ "#{tag_name}[]"
+ end
+
+ @template_object.hidden_field_tag(hidden_name, "", id: nil)
+ end
end
end
end