Class: Terrazzo::Field::HasOne
Constant Summary
Constants inherited
from Base
Base::ABSTRACT_FIELD_CLASSES
Instance Attribute Summary
Attributes inherited from Base
#attribute, #data, #options, #page, #resource
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Associative
associative?, eager_load?
Methods inherited from Base
associative?, default_options, eager_load?, #field_type, field_type, #form_input_attributes, #initialize, #required?, searchable?, transform_param, with_options
Class Method Details
.permitted_attribute(attr, _options = {}) ⇒ Object
24
25
26
|
# File 'lib/terrazzo/field/has_one.rb', line 24
def permitted_attribute(attr, _options = {})
:"#{attr}_id"
end
|
20
21
22
|
# File 'lib/terrazzo/field/has_one.rb', line 20
def sortable?
false
end
|
Instance Method Details
#serializable_options(page = nil) ⇒ Object
14
15
16
17
|
# File 'lib/terrazzo/field/has_one.rb', line 14
def serializable_options(page = nil)
return {} unless page == :form && resource
{ resourceOptions: resource_options }
end
|
#serialize_value(mode) ⇒ Object
4
5
6
7
8
9
10
11
12
|
# File 'lib/terrazzo/field/has_one.rb', line 4
def serialize_value(mode)
case mode
when :form
data&.id&.to_s
else
return nil if data.nil?
{ id: data.id.to_s, display: display_name(data) }
end
end
|