Class: RailsAdmin::Config::Fields::Types::PolymorphicAssociation
- Inherits:
-
BelongsToAssociation
- Object
- Base
- Base
- Association
- BelongsToAssociation
- RailsAdmin::Config::Fields::Types::PolymorphicAssociation
- Defined in:
- lib/rails_admin/config/fields/types/polymorphic_association.rb
Instance Attribute Summary
Attributes inherited from Base
#defined, #name, #order, #properties
Attributes inherited from Base
#abstract_model, #bindings, #parent, #root
Instance Method Summary collapse
- #associated_collection(type) ⇒ Object
- #associated_model_config ⇒ Object
- #polymorphic_type_collection ⇒ Object
- #polymorphic_type_urls ⇒ Object
-
#value ⇒ Object
Reader for field’s value.
Methods inherited from BelongsToAssociation
Methods inherited from Association
#associated_label_method, #association, #child_key, #errors, inherited, #inverse_of, #polymorphic?
Methods inherited from Base
#association?, #column_css_class, #dom_id, #dom_name, #errors, #has_errors?, inherited, #initialize, #method_name, #optional, #optional=, #optional?, #type, #virtual?
Methods included from Hideable
#hidden?, #hide, included, #show
Methods inherited from Base
#has_option?, #initialize, register_class_option, #register_deprecated_instance_option, register_deprecated_instance_option, #register_instance_option, register_instance_option, #with
Constructor Details
This class inherits a constructor from RailsAdmin::Config::Fields::Base
Instance Method Details
#associated_collection(type) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 42 def associated_collection(type) return [] if type.nil? config = RailsAdmin.config(type) config.abstract_model.all.map do |object| [object.send(config.object_label_method), object.id] end end |
#associated_model_config ⇒ Object
50 51 52 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 50 def associated_model_config @associated_model_config ||= association[:parent_model].map{|type| RailsAdmin.config(type) }.select{|config| !config.excluded? } end |
#polymorphic_type_collection ⇒ Object
54 55 56 57 58 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 54 def polymorphic_type_collection associated_model_config.map do |config| [config.label, config.abstract_model.model.name] end end |
#polymorphic_type_urls ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 60 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 |
#value ⇒ Object
Reader for field’s value
71 72 73 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 71 def value bindings[:object].send(association[:name]) end |