Class: Madmin::Fields::BelongsTo
Instance Attribute Summary
#attribute_name, #model, #options, #resource
Instance Method Summary
collapse
#default_index_attributes, field_type, #initialize, #paginateable?, #required?, #searchable?, #to_partial_path, #value, #visible?
Constructor Details
This class inherits a constructor from Madmin::Field
Instance Method Details
#associated_resource ⇒ Object
18
19
20
21
|
# File 'lib/madmin/fields/belongs_to.rb', line 18
def associated_resource
Madmin.resource_by_name(model.reflect_on_association(attribute_name).klass)
rescue MissingResource
end
|
#associated_resource_for(object) ⇒ Object
#index_path(format: :json) ⇒ Object
14
15
16
|
# File 'lib/madmin/fields/belongs_to.rb', line 14
def index_path(format: :json)
associated_resource&.index_path(format: format)
end
|
#options_for_select(record) ⇒ Object
4
5
6
7
8
|
# File 'lib/madmin/fields/belongs_to.rb', line 4
def options_for_select(record)
current_value = record.send(attribute_name)
records = [current_value].compact + associated_resource.model.excluding(current_value).limit(25)
records.map { [Madmin.resource_for(_1).display_name(_1), _1.id] }
end
|
#to_param ⇒ Object
10
11
12
|
# File 'lib/madmin/fields/belongs_to.rb', line 10
def to_param
"#{attribute_name}_id"
end
|