Module: Para::Admin::NestedInputsHelper

Defined in:
app/helpers/para/admin/nested_inputs_helper.rb

Instance Method Summary collapse

Instance Method Details

#with_inverse_association_for(resource, attribute_name, parent_resource) ⇒ Object

Helper that allows filling a parent association for a given resource, based on the inverse_of option of the parent resource association.



7
8
9
10
11
12
13
14
# File 'app/helpers/para/admin/nested_inputs_helper.rb', line 7

def with_inverse_association_for(resource, attribute_name, parent_resource)
  resource.tap do
    association_name = parent_resource.association(attribute_name).options[:inverse_of]
    return resource unless association_name

    resource.association(association_name).send(:replace, parent_resource)
  end
end