aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_view/helpers/tags/base.rb6
-rw-r--r--actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb12
-rw-r--r--actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb30
3 files changed, 26 insertions, 22 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb
index 449f94d347..ec8e3caf3a 100644
--- a/actionpack/lib/action_view/helpers/tags/base.rb
+++ b/actionpack/lib/action_view/helpers/tags/base.rb
@@ -78,7 +78,7 @@ module ActionView
options["name"] ||= tag_name_with_index(@auto_index)
options["id"] = options.fetch("id"){ tag_id_with_index(@auto_index) }
else
- options["name"] ||= tag_name + (options['multiple'] ? '[]' : '')
+ options["name"] ||= options['multiple'] ? tag_name_multiple : tag_name
options["id"] = options.fetch("id"){ tag_id }
end
options["id"] = [options.delete('namespace'), options["id"]].compact.join("_").presence
@@ -88,6 +88,10 @@ module ActionView
"#{@object_name}[#{sanitized_method_name}]"
end
+ def tag_name_multiple
+ "#{tag_name}[]"
+ end
+
def tag_name_with_index(index)
"#{@object_name}[#{index}][#{sanitized_method_name}]"
end
diff --git a/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb
index ae27c4e6da..1103341888 100644
--- a/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb
+++ b/actionpack/lib/action_view/helpers/tags/collection_check_boxes.rb
@@ -9,18 +9,18 @@ module ActionView
default_html_options[:multiple] = true
if block_given?
- yield sanitize_attribute_name(@method_name, value), text, value, default_html_options
+ yield sanitize_attribute_name(value), text, value, default_html_options
else
check_box(@object_name, @method_name, default_html_options, value, nil) +
- label(@object_name, sanitize_attribute_name(@method_name, value), text, :class => "collection_check_boxes")
+ label(@object_name, sanitize_attribute_name(value), text, :class => "collection_check_boxes")
end
end
- # Prepend a hidden field to make sure something will be sent back to the
- # server if all checkboxes are unchecked.
- hidden = @template_object.hidden_field_tag("#{@object_name}[#{@method_name}][]", "", :id => nil)
+ # 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_multiple, "", :id => nil)
- wrap_rendered_collection(rendered_collection + hidden, @options)
+ wrap_rendered_collection(rendered_collection + hidden)
end
end
end
diff --git a/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb b/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb
index 0b83d3482c..cd02408833 100644
--- a/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb
+++ b/actionpack/lib/action_view/helpers/tags/collection_radio_buttons.rb
@@ -7,31 +7,31 @@ module ActionView
def render
rendered_collection = render_collection do |value, text, default_html_options|
if block_given?
- yield sanitize_attribute_name(@method_name, value), text, value, default_html_options
+ yield sanitize_attribute_name(value), text, value, default_html_options
else
radio_button(@object_name, @method_name, value, default_html_options) +
- label(@object_name, sanitize_attribute_name(@method_name, value), text, :class => "collection_radio_buttons")
+ label(@object_name, sanitize_attribute_name(value), text, :class => "collection_radio_buttons")
end
end
- wrap_rendered_collection(rendered_collection, @options)
+ wrap_rendered_collection(rendered_collection)
end
private
# Generate default options for collection helpers, such as :checked and
# :disabled.
- def default_html_options_for_collection(item, value, options, html_options) #:nodoc:
- html_options = html_options.dup
+ def default_html_options_for_collection(item, value) #:nodoc:
+ html_options = @html_options.dup
[:checked, :selected, :disabled].each do |option|
- next unless options[option]
+ next unless @options[option]
- accept = if options[option].respond_to?(:call)
- options[option].call(item)
+ accept = if @options[option].respond_to?(:call)
+ @options[option].call(item)
else
- Array(options[option]).include?(value)
+ Array(@options[option]).include?(value)
end
if accept
@@ -44,8 +44,8 @@ module ActionView
html_options
end
- def sanitize_attribute_name(attribute, value) #:nodoc:
- "#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase}"
+ def sanitize_attribute_name(value) #:nodoc:
+ "#{sanitized_method_name}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase}"
end
def render_collection #:nodoc:
@@ -55,7 +55,7 @@ module ActionView
@collection.map do |item|
value = value_for_collection(item, @value_method)
text = value_for_collection(item, @text_method)
- default_html_options = default_html_options_for_collection(item, value, @options, @html_options)
+ default_html_options = default_html_options_for_collection(item, value)
rendered_item = yield value, text, default_html_options
@@ -67,11 +67,11 @@ module ActionView
value.respond_to?(:call) ? value.call(item) : item.send(value)
end
- def wrap_rendered_collection(collection, options)
- wrapper_tag = options[:collection_wrapper_tag]
+ def wrap_rendered_collection(collection)
+ wrapper_tag = @options[:collection_wrapper_tag]
if wrapper_tag
- wrapper_class = options[:collection_wrapper_class]
+ wrapper_class = @options[:collection_wrapper_class]
@template_object.content_tag(wrapper_tag, collection, :class => wrapper_class)
else
collection