class ActiveAdmin::Resource::BelongsTo
Attributes
The resource which initiated this relationship
The name of the relation
Public Class Methods
Source
# File lib/active_admin/resource/belongs_to.rb, line 20 def initialize(owner, target_name, options = {}) @owner = owner @target_name = target_name @options = options end
Public Instance Methods
Source
# File lib/active_admin/resource/belongs_to.rb, line 36 def namespace @owner.namespace end
Source
# File lib/active_admin/resource/belongs_to.rb, line 40 def optional? @options[:optional] end
Source
# File lib/active_admin/resource/belongs_to.rb, line 44 def required? !optional? end
Source
# File lib/active_admin/resource/belongs_to.rb, line 31 def resource namespace.resources[@options[:class_name]] || namespace.resources[@target_name.to_s.camelize] end
Source
# File lib/active_admin/resource/belongs_to.rb, line 27 def target resource or raise TargetNotFound.new (@options[:class_name] || @target_name.to_s.camelize), namespace end
Returns the target resource class or raises an exception if it doesn’t exist
Source
# File lib/active_admin/resource/belongs_to.rb, line 48 def to_param (@options[:param] || "#{@target_name}_id").to_sym end