Class: Administrate::Field::LazyBelongsTo

Inherits:
BelongsTo
  • Object
show all
Includes:
LazyBelongsToVersion
Defined in:
lib/administrate/field/lazy_belongs_to.rb

Defined Under Namespace

Classes: Engine

Constant Summary

Constants included from LazyBelongsToVersion

Administrate::Field::LazyBelongsToVersion::VERSION

Instance Method Summary collapse

Instance Method Details

#current_valueObject



28
29
30
# File 'lib/administrate/field/lazy_belongs_to.rb', line 28

def current_value
  data ? display_associated_resource : display_placeholder
end

#display_placeholderObject



22
23
24
25
26
# File 'lib/administrate/field/lazy_belongs_to.rb', line 22

def display_placeholder
  options.fetch(:placeholder) do
    format('Select a %<association>s', association: associated_class.name)
  end
end

#label_attributeObject



40
41
42
# File 'lib/administrate/field/lazy_belongs_to.rb', line 40

def label_attribute
  options.fetch(:label_attribute) { 'name' }
end

#sizeObject



44
45
46
# File 'lib/administrate/field/lazy_belongs_to.rb', line 44

def size
  options.fetch(:size) { 10 }
end

#templated_actionObject



32
33
34
# File 'lib/administrate/field/lazy_belongs_to.rb', line 32

def templated_action
  options.fetch(:action).call(self, q: '{q}')
end

#to_sObject



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

def to_s
  data
end

#url_helpersObject



48
49
50
# File 'lib/administrate/field/lazy_belongs_to.rb', line 48

def url_helpers
  Rails.application.routes.url_helpers
end

#value_attributeObject



36
37
38
# File 'lib/administrate/field/lazy_belongs_to.rb', line 36

def value_attribute
  options.fetch(:value_attribute) { 'id' }
end