class ActiveAdmin::Resource::BelongsTo

Attributes

owner[R]

The resource which initiated this relationship

target_name[R]

The name of the relation

Public Class Methods

new(owner, target_name, options = {}) click to toggle source
# File lib/active_admin/resource/belongs_to.rb, line 21
def initialize(owner, target_name, options = {})
  @owner = owner
  @target_name = target_name
  @options = options
end

Public Instance Methods

namespace() click to toggle source
# File lib/active_admin/resource/belongs_to.rb, line 37
def namespace
  @owner.namespace
end
optional?() click to toggle source
# File lib/active_admin/resource/belongs_to.rb, line 41
def optional?
  @options[:optional]
end
required?() click to toggle source
# File lib/active_admin/resource/belongs_to.rb, line 45
def required?
  !optional?
end
resource() click to toggle source
# File lib/active_admin/resource/belongs_to.rb, line 32
def resource
  namespace.resources[@options[:class_name]] ||
    namespace.resources[@target_name.to_s.camelize]
end
target() click to toggle source

Returns the target resource class or raises an exception if it doesn’t exist

# File lib/active_admin/resource/belongs_to.rb, line 28
def target
  resource or raise TargetNotFound.new (@options[:class_name] || @target_name.to_s.camelize), namespace
end
to_param() click to toggle source
# File lib/active_admin/resource/belongs_to.rb, line 49
def to_param
  (@options[:param] || "#{@target_name}_id").to_sym
end