Class: Administrate::Field::BelongsTo
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, #html_controller, reflection
Methods inherited from Base
associative?, field_type, html_class, #html_class, #html_controller, #initialize, #name, #read_value, #required?, searchable?, #to_partial_path, with_options
Class Method Details
.eager_load? ⇒ Boolean
16
17
18
|
# File 'lib/administrate/field/belongs_to.rb', line 16
def self.eager_load?
true
end
|
.permitted_attribute(attr, options = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/administrate/field/belongs_to.rb', line 6
def self.permitted_attribute(attr, options = {})
resource_class = options[:resource_class]
if resource_class
foreign_key_for(resource_class, attr)
else
Administrate.warn_of_missing_resource_class
:"#{attr}_id"
end
end
|
Instance Method Details
#associated_resource_options ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/administrate/field/belongs_to.rb', line 24
def associated_resource_options
candidate_resources.map do |resource|
[
display_candidate_resource(resource),
resource.send(association_primary_key)
]
end
end
|
#include_blank_option ⇒ Object
37
38
39
|
# File 'lib/administrate/field/belongs_to.rb', line 37
def include_blank_option
options.fetch(:include_blank, true)
end
|
#permitted_attribute ⇒ Object
20
21
22
|
# File 'lib/administrate/field/belongs_to.rb', line 20
def permitted_attribute
foreign_key
end
|
#selected_option ⇒ Object
33
34
35
|
# File 'lib/administrate/field/belongs_to.rb', line 33
def selected_option
data&.send(association_primary_key)
end
|