Class: Administrate::Field::LazyHasMany

Inherits:
HasMany
  • Object
show all
Includes:
LazyHasManyVersion
Defined in:
lib/administrate/field/lazy_has_many.rb

Defined Under Namespace

Classes: Engine

Constant Summary

Constants included from LazyHasManyVersion

Administrate::Field::LazyHasManyVersion::VERSION

Instance Method Summary collapse

Instance Method Details

#actionObject



31
32
33
34
35
# File 'lib/administrate/field/lazy_has_many.rb', line 31

def action
  raise StandardError.new 'action is missing' if options[:action].blank?

  Rails.application.routes.url_helpers.send(options[:action])
end

#candidate_resourcesObject



14
15
16
17
18
19
20
21
# File 'lib/administrate/field/lazy_has_many.rb', line 14

def candidate_resources
  if options.key?(:includes)
    includes = options.fetch(:includes)
    associated_class.includes(*includes).where(id: data.map(&:id))
  else
    associated_class.where(id: data.map(&:id))
  end
end

#custom_attribute_idObject



23
24
25
# File 'lib/administrate/field/lazy_has_many.rb', line 23

def custom_attribute_id
  "#{resource.class.name.underscore}_#{attribute_key}"
end

#result_limitObject



37
38
39
# File 'lib/administrate/field/lazy_has_many.rb', line 37

def result_limit
  options[:result_limit] || 10
end

#to_sObject



27
28
29
# File 'lib/administrate/field/lazy_has_many.rb', line 27

def to_s
  data.map { |v| display_candidate_resource(v) }
end