Class: Para::AttributeField::NestedManyField

Inherits:
AttributeField::HasManyField
  • Object
show all
Includes:
NestedField, Helpers::AttributesMappings
Defined in:
lib/para/attribute_field/nested_many.rb

Instance Method Summary collapse

Methods included from NestedField

#nested_attributes_key, #nested_model_mappings, #temporarily_extend_new_resource

Methods included from Helpers::AttributesMappings

#attributes_mappings_for

Instance Method Details

#parse_input(params, resource) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/para/attribute_field/nested_many.rb', line 9

def parse_input(params, resource)
  if (nested_attributes = params[nested_attributes_key])
    nested_attributes.each do |index, attributes|
      nested_resource = fetch_or_build_nested_resource_for(resource, index, attributes)
      mappings = nested_model_mappings(attributes, nested_resource)

      mappings.fields.each do |field|
        field.parse_input(attributes, nested_resource)
      end

      params[nested_attributes_key][index] = attributes
    end
  else
    super
  end
end