instance method fields_for_with_nested_attributes

Ruby on Rails 8.0.4

Since v3.0.20 Private

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

fields_for_with_nested_attributes(association_name, association, options, block)

No documentation comment.

Parameters

association_name req
association req
options req
block req
Source
# File actionview/lib/action_view/helpers/form_helper.rb, line 2709
        def fields_for_with_nested_attributes(association_name, association, options, block)
          name = "#{object_name}[#{association_name}_attributes]"
          association = convert_to_model(association)

          if association.respond_to?(:persisted?)
            association = [association] if @object.public_send(association_name).respond_to?(:to_ary)
          elsif !association.respond_to?(:to_ary)
            association = @object.public_send(association_name)
          end

          if association.respond_to?(:to_ary)
            explicit_child_index = options[:child_index]
            output = ActiveSupport::SafeBuffer.new
            association.each do |child|
              if explicit_child_index
                options[:child_index] = explicit_child_index.call if explicit_child_index.respond_to?(:call)
              else
                options[:child_index] = nested_child_index(name)
              end
              if content = fields_for_nested_model("#{name}[#{options[:child_index]}]", child, options, block)
                output << content
              end
            end
            output
          elsif association
            fields_for_nested_model(name, association, options, block)
          end
        end

Defined in actionview/lib/action_view/helpers/form_helper.rb line 2709 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::FormBuilder

Type at least 2 characters to search.

↑↓ navigate · open · esc close