Class: RailsAdmin::Config::Fields::Types::PolymorphicAssociation
- Inherits:
-
BelongsToAssociation
- Object
- Base
- Association
- BelongsToAssociation
- RailsAdmin::Config::Fields::Types::PolymorphicAssociation
- Defined in:
- lib/rails_admin/config/fields/types/polymorphic_association.rb
Constant Summary
Constants inherited from Base
Base::NAMED_INSTANCE_VARIABLES
Instance Attribute Summary
Attributes inherited from Base
#abstract_model, #defined, #name, #order, #parent, #properties, #root, #section
Instance Method Summary collapse
- #associated_collection(type) ⇒ Object
- #associated_model_config ⇒ Object
- #parse_input(params) ⇒ Object
- #polymorphic_type_collection ⇒ Object
- #polymorphic_type_urls ⇒ Object
-
#value ⇒ Object
Reader for field’s value.
Methods inherited from BelongsToAssociation
#method_name, #multiple?, #selected_id
Methods inherited from Association
#associated_model_limit, #associated_object_label_method, #associated_prepopulate_params, #associated_primary_key, #association, #method_name, #multiple?, #polymorphic?, #virtual?
Methods inherited from Base
#association?, #eager_load_values, #editable?, #errors, #filter_options, #form_default_value, #form_value, #generic_field_help, #generic_help, #initialize, #inverse_of, #method_name, #optional, #optional=, #optional?, #parse_value, #sort_column, #type, #type_css_class, #virtual?
Methods included from Inspectable
Methods included from Groupable
Methods included from Hideable
#hidden?, #hide, included, #show
Methods included from Configurable
#has_option?, included, #register_deprecated_instance_option, #register_instance_option
Methods included from Proxyable
Constructor Details
This class inherits a constructor from RailsAdmin::Config::Fields::Base
Instance Method Details
#associated_collection(type) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 54 def associated_collection(type) return [] if type.blank? config = RailsAdmin.config(type) config.abstract_model.all.collect do |object| [object.send(config.object_label_method), object.id] end end |
#associated_model_config ⇒ Object
63 64 65 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 63 def associated_model_config @associated_model_config ||= association.klass.collect { |type| RailsAdmin.config(type) }.reject(&:excluded?) end |
#parse_input(params) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 85 def parse_input(params) if (type_value = params[association.foreign_type.to_sym]).present? config = associated_model_config.find { |c| type_value == c.abstract_model.model.name } params[association.foreign_type.to_sym] = config.abstract_model.base_class.name if config end end |
#polymorphic_type_collection ⇒ Object
67 68 69 70 71 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 67 def polymorphic_type_collection associated_model_config.collect do |config| [config.label, config.abstract_model.model.name] end end |
#polymorphic_type_urls ⇒ Object
73 74 75 76 77 78 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 73 def polymorphic_type_urls types = associated_model_config.collect 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
81 82 83 |
# File 'lib/rails_admin/config/fields/types/polymorphic_association.rb', line 81 def value bindings[:object].send(association.name) end |