Class: RailsAdmin::Config::Fields::Types::PolymorphicAssociation

Inherits:
BelongsToAssociation show all
Defined in:
lib/rails_admin/config/fields/types/polymorphic_association.rb

Instance Attribute Summary

Attributes inherited from Base

#abstract_model, #defined, #name, #order, #parent, #properties, #root, #section

Attributes included from Proxyable

#bindings

Instance Method Summary collapse

Methods inherited from BelongsToAssociation

#method_name, #multiple?, #selected_id

Methods inherited from Association

#associated_object_label_method, #associated_primary_key, #association, #foreign_key, #multiple?, #polymorphic?, #virtual?

Methods inherited from Base

#association?, #editable?, #errors, #html_default_value, #initialize, #inspect, #inverse_of, #method_name, #optional, #optional=, #optional?, #type, #type_css_class, #virtual?

Methods included from Groupable

#group

Methods included from Hideable

#hidden?, #hide, included, #show

Methods included from Configurable

#has_option?, #register_deprecated_instance_option, #register_instance_option

Methods included from Proxyable

#with

Constructor Details

This class inherits a constructor from RailsAdmin::Config::Fields::Base

Instance Method Details

#associated_collection(type) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 40

def associated_collection(type)
  return [] if type.blank?
  config = RailsAdmin.config(type)
  config.abstract_model.all.map do |object|
    [object.send(config.object_label_method), object.id]
  end
end

#associated_model_configObject



48
49
50
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 48

def associated_model_config
  @associated_model_config ||= association[:model_proc].call.map{|type| RailsAdmin.config(type) }.select{|config| !config.excluded? }
end

#polymorphic_type_collectionObject



52
53
54
55
56
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 52

def polymorphic_type_collection
  associated_model_config.map do |config|
    [config.label, config.abstract_model.model.name]
  end
end

#polymorphic_type_urlsObject



58
59
60
61
62
63
64
65
66
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 58

def polymorphic_type_urls
  types = associated_model_config.map do |config|
    [config.abstract_model.model.name, config.abstract_model.to_param]
  end

  ::Hash[*types.collect { |v|
        [v[0], bindings[:view].index_path(v[1])]
      }.flatten]
end

#valueObject

Reader for field's value



69
70
71
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 69

def value
  bindings[:object].send(association[:name])
end