Class: Administrate::Field::BelongsTo

Inherits:
Associative show all
Defined in:
lib/administrate/field/belongs_to.rb

Direct Known Subclasses

Polymorphic

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, local_partial_prefixes, #name, partial_prefixes, #partial_prefixes, #read_value, #required?, searchable?, sortable?, with_options

Constructor Details

This class inherits a constructor from Administrate::Field::Base

Class Method Details

.eager_load?Boolean

Returns:



11
12
13
# File 'lib/administrate/field/belongs_to.rb', line 11

def self.eager_load?
  true
end

.permitted_attribute(attr, options = {}) ⇒ Object



6
7
8
9
# File 'lib/administrate/field/belongs_to.rb', line 6

def self.permitted_attribute(attr, options = {})
  resource_class = options[:resource_class]
  foreign_key_for(resource_class, attr)
end

Instance Method Details

#associated_resource_optionsObject



19
20
21
22
23
24
25
26
# File 'lib/administrate/field/belongs_to.rb', line 19

def associated_resource_options
  candidate_resources.map do |resource|
    [
      display_candidate_resource(resource),
      resource.send(association_primary_key)
    ]
  end
end

#include_blank_optionObject



32
33
34
# File 'lib/administrate/field/belongs_to.rb', line 32

def include_blank_option
  options.fetch(:include_blank, true)
end

#permitted_attributeObject



15
16
17
# File 'lib/administrate/field/belongs_to.rb', line 15

def permitted_attribute
  foreign_key
end

#selected_optionObject



28
29
30
# File 'lib/administrate/field/belongs_to.rb', line 28

def selected_option
  data&.send(association_primary_key)
end