Class: Para::AttributeField::BelongsToField
Instance Attribute Summary
Attributes inherited from Base
#field_method, #field_type, #model, #name, #type
Instance Method Summary
collapse
Methods inherited from Base
#attribute_column_path, #determine_name_and_field_method!, field_option, #field_options, field_types, #initialize, register, #type?
Instance Method Details
#field_name ⇒ Object
8
9
10
|
# File 'lib/para/attribute_field/belongs_to.rb', line 8
def field_name
reflection.name
end
|
22
23
24
25
26
27
28
|
# File 'lib/para/attribute_field/belongs_to.rb', line 22
def parse_input(params)
if (id = params[reflection.foreign_key].presence) && !reflection.klass.exists?(id: id)
on_the_fly_creation(id) do |resource|
params[reflection.foreign_key] = resource.id
end
end
end
|
#relation_options ⇒ Object
18
19
20
|
# File 'lib/para/attribute_field/belongs_to.rb', line 18
def relation_options
reflection.klass.all
end
|
#value_for(instance) ⇒ Object
12
13
14
15
16
|
# File 'lib/para/attribute_field/belongs_to.rb', line 12
def value_for(instance)
if (resource = instance.send(name))
resource_name(resource)
end
end
|