Module: ActionView::Helpers::Tags::CollectionHelpers
Do not use. This module is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | actionview/lib/action_view/helpers/tags/collection_helpers.rb |
Instance Method Summary
- #initialize(object_name, method_name, template_object, collection, value_method, text_method, options, html_options)
-
#default_html_options_for_collection(item, value)
private
Generate default options for collection helpers, such as
:checked
and:disabled
. - #hidden_field private
- #hidden_field_name private
- #instantiate_builder(builder_class, item, value, text, html_options) private
- #render_collection private
- #render_collection_for(builder_class, &block) private
- #sanitize_attribute_name(value) private
Instance Method Details
#default_html_options_for_collection(item, value) (private)
Generate default options for collection helpers, such as :checked
and :disabled
.
# File 'actionview/lib/action_view/helpers/tags/collection_helpers.rb', line 47
def (item, value) = @html_options.dup [:checked, :selected, :disabled, :readonly].each do |option| current_value = @options[option] next if current_value.nil? accept = if current_value.respond_to?(:call) current_value.call(item) else Array(current_value).map(&:to_s).include?(value.to_s) end if accept [option] = true elsif option == :checked [option] = false end end [:object] = @object end
#initialize(object_name, method_name, template_object, collection, value_method, text_method, options, html_options)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/collection_helpers.rb', line 30
def initialize(object_name, method_name, template_object, collection, value_method, text_method, , ) @collection = collection @value_method = value_method @text_method = text_method @html_options = super(object_name, method_name, template_object, ) end
#instantiate_builder(builder_class, item, value, text, html_options) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/collection_helpers.rb', line 40
def instantiate_builder(builder_class, item, value, text, ) builder_class.new(@template_object, @object_name, @method_name, item, sanitize_attribute_name(value), text, value, ) end
#render_collection (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/collection_helpers.rb', line 75
def render_collection @collection.map do |item| value = value_for_collection(item, @value_method) text = value_for_collection(item, @text_method) = (item, value) = option_html_attributes(item) yield item, value, text, .merge( ) end.join.html_safe end
#render_collection_for(builder_class, &block) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/collection_helpers.rb', line 86
def render_collection_for(builder_class, &block) = @options.stringify_keys rendered_collection = render_collection do |item, value, text, | builder = instantiate_builder(builder_class, item, value, text, ) if block_given? @template_object.capture(builder, &block) else render_component(builder) end end # Prepend a hidden field to make sure something will be sent back to the # server if all radio buttons are unchecked. if .fetch("include_hidden", true) hidden_field + rendered_collection else rendered_collection end end
#sanitize_attribute_name(value) (private)
[ GitHub ]# File 'actionview/lib/action_view/helpers/tags/collection_helpers.rb', line 71
def sanitize_attribute_name(value) "#{sanitized_method_name}_#{sanitized_value(value)}" end