Sha256: db01078c286c48ec9ac24b3145471822c2054ae2fb5cf4bcb8cfd460a9fa4f69
Contents?: true
Size: 870 Bytes
Versions: 13
Compression:
Stored size: 870 Bytes
Contents
require_relative "associative" module Administrate module Field class BelongsTo < Associative def self.permitted_attribute(attr, _options = nil) :"#{attr}_id" end def permitted_attribute foreign_key end def associated_resource_options [nil] + candidate_resources.map do |resource| [display_candidate_resource(resource), resource.send(primary_key)] end end def selected_option data && data.send(primary_key) end private def candidate_resources scope = options[:scope] ? options[:scope].call : associated_class.all order = options.delete(:order) order ? scope.reorder(order) : scope end def display_candidate_resource(resource) associated_dashboard.display_resource(resource) end end end end
Version data entries
13 entries across 13 versions & 3 rubygems