Class: Para::AttributeField::NestedManyField

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

Instance Attribute Summary

Attributes inherited from Base

#field_method, #field_type, #model, #name, #options, #type

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

Methods inherited from HasManyField

#assign_ids, #assign_ordered_through_reflection_ids, #field_name, #plural_foreign_key, #value_for

Methods inherited from RelationField

#foreign_key, #polymorphic_through_reflection?, #reflection, #through_reflection, #through_relation, #through_relation_source_foreign_key

Methods included from Helpers::ResourceName

#resource_name

Methods inherited from Base

#attribute_column_path, #determine_name_and_field_method!, #excerptable_value?, #field_name, field_option, #field_options, field_types, #initialize, register, #searchable?, #type?, #value_for

Constructor Details

This class inherits a constructor from Para::AttributeField::Base

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