Class: Administrate::Field::Associative

Inherits:
Base
  • Object
show all
Defined in:
lib/administrate/field/associative.rb

Direct Known Subclasses

BelongsTo, HasMany, HasOne

Instance Attribute Summary

Attributes inherited from Base

#attribute, #data, #options, #page, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

associative?, eager_load?, field_type, html_class, #html_class, #initialize, #name, permitted_attribute, #required?, searchable?, #to_partial_path, with_options

Constructor Details

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

Class Method Details

.associated_class(resource_class, attr) ⇒ Object



10
11
12
# File 'lib/administrate/field/associative.rb', line 10

def self.associated_class(resource_class, attr)
  reflection(resource_class, attr).klass
end

.associated_class_name(resource_class, attr) ⇒ Object



14
15
16
# File 'lib/administrate/field/associative.rb', line 14

def self.associated_class_name(resource_class, attr)
  associated_class(resource_class, attr).name
end

.foreign_key_for(resource_class, attr) ⇒ Object



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

def self.foreign_key_for(resource_class, attr)
  reflection(resource_class, attr).foreign_key
end

.reflection(resource_class, attr) ⇒ Object



18
19
20
# File 'lib/administrate/field/associative.rb', line 18

def self.reflection(resource_class, attr)
  resource_class.reflect_on_association(attr)
end

Instance Method Details

#associated_classObject



26
27
28
29
30
31
32
# File 'lib/administrate/field/associative.rb', line 26

def associated_class
  if option_given?(:class_name)
    associated_class_name.constantize
  else
    self.class.associated_class(resource.class, attribute)
  end
end

#associated_class_nameObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/administrate/field/associative.rb', line 34

def associated_class_name
  if option_given?(:class_name)
    deprecated_option(:class_name)
  else
    self.class.associated_class_name(
      resource.class,
      attribute,
    )
  end
end

#display_associated_resourceObject



22
23
24
# File 'lib/administrate/field/associative.rb', line 22

def display_associated_resource
  associated_dashboard.display_resource(data)
end