Class: Administrate::Field::HasOne
Instance Attribute Summary
Attributes inherited from Base
#attribute, #data, #options, #page, #resource
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Associative
associated_class, #associated_class, #associated_class_name, associated_class_name, association_primary_key_for, #display_associated_resource, foreign_key_for, reflection
Methods inherited from Base
associative?, field_type, html_class, #html_class, #initialize, local_partial_prefixes, #name, partial_prefixes, #partial_prefixes, #read_value, #required?, searchable?, sortable?, with_options
Class Method Details
.eager_load? ⇒ Boolean
21
22
23
|
# File 'lib/administrate/field/has_one.rb', line 21
def self.eager_load?
true
end
|
.permitted_attribute(attr, options = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/administrate/field/has_one.rb', line 6
def self.permitted_attribute(attr, options = {})
resource_class = options[:resource_class]
final_associated_class_name =
if options.key?(:class_name)
options.fetch(:class_name)
else
associated_class_name(resource_class, attr)
end
related_dashboard_attributes =
Administrate::ResourceResolver
.new("admin/#{final_associated_class_name}")
.dashboard_class.new.permitted_attributes + [:id]
{"#{attr}_attributes": related_dashboard_attributes}
end
|
Instance Method Details
#html_controller ⇒ Object
43
44
45
|
# File 'lib/administrate/field/has_one.rb', line 43
def html_controller
"select"
end
|
39
40
41
|
# File 'lib/administrate/field/has_one.rb', line 39
def linkable?
data.try(:persisted?)
end
|
25
26
27
28
29
30
|
# File 'lib/administrate/field/has_one.rb', line 25
def nested_form
@nested_form ||= Administrate::Page::Form.new(
resolver.dashboard_class.new,
data || resolver.resource_class.new
)
end
|
#nested_show ⇒ Object
32
33
34
35
36
37
|
# File 'lib/administrate/field/has_one.rb', line 32
def nested_show
@nested_show ||= Administrate::Page::Show.new(
resolver.dashboard_class.new,
data || resolver.resource_class.new
)
end
|