class Administrate::Field::BelongsTo

Public Class Methods

eager_load?() click to toggle source
# File lib/administrate/field/belongs_to.rb, line 16
def self.eager_load?
  true
end
permitted_attribute(attr, options = {}) click to toggle source
# 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

Public Instance Methods

associated_resource_options() click to toggle source
# 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() click to toggle source
# File lib/administrate/field/belongs_to.rb, line 37
def include_blank_option
  options.fetch(:include_blank, true)
end
permitted_attribute() click to toggle source
# File lib/administrate/field/belongs_to.rb, line 20
def permitted_attribute
  foreign_key
end
selected_option() click to toggle source
# File lib/administrate/field/belongs_to.rb, line 33
def selected_option
  data&.send(association_primary_key)
end

Private Instance Methods

candidate_resources() click to toggle source
# File lib/administrate/field/belongs_to.rb, line 43
def candidate_resources
  scope = options[:scope] ? options[:scope].call : associated_class.all

  order = options.delete(:order)
  order ? scope.reorder(order) : scope
end
display_candidate_resource(resource) click to toggle source
# File lib/administrate/field/belongs_to.rb, line 50
def display_candidate_resource(resource)
  associated_dashboard.display_resource(resource)
end