Class: Madmin::Fields::HasMany
- Inherits:
-
Madmin::Field
- Object
- Madmin::Field
- Madmin::Fields::HasMany
- Defined in:
- lib/madmin/fields/has_many.rb
Instance Attribute Summary
Attributes inherited from Madmin::Field
#attribute_name, #model, #options, #resource
Instance Method Summary collapse
Methods inherited from Madmin::Field
#default_index_attributes, field_type, #initialize, #required?, #searchable?, #to_partial_path, #value, #visible?
Constructor Details
This class inherits a constructor from Madmin::Field
Instance Method Details
#index_path ⇒ Object
18 19 20 |
# File 'lib/madmin/fields/has_many.rb', line 18 def index_path Madmin.resource_by_name(model.reflect_on_association(attribute_name).klass).index_path(format: :json) end |
#options_for_select(record) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/madmin/fields/has_many.rb', line 4 def (record) if (records = record.send(attribute_name)) return [] unless records.first resource = Madmin.resource_for(records.first) records.map { |record| [resource.display_name(record), record.id] } else [] end end |
#to_param ⇒ Object
14 15 16 |
# File 'lib/madmin/fields/has_many.rb', line 14 def to_param {"#{attribute_name.to_s.singularize}_ids": []} end |