Module: Madmin::Field::Associatable
Class Method Summary collapse
Instance Method Summary collapse
- #association_collection ⇒ Object
- #association_id_for(resource) ⇒ Object
- #association_id_or_blank_for(resource) ⇒ Object
- #association_param ⇒ Object
- #association_slug ⇒ Object
- #association_value_for(resource) ⇒ Object
- #initialize(args) ⇒ Object
- #strong_params_keys ⇒ Object
Class Method Details
.included(_base) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/madmin/field/associatable.rb', line 5 def included(_base) attr_reader :association_class attr_reader :association_display_value attr_reader :association_foreign_key attr_reader :association_scope end |
Instance Method Details
#association_collection ⇒ Object
18 19 20 |
# File 'lib/madmin/field/associatable.rb', line 18 def association_collection association_class.send(association_scope) end |
#association_id_for(resource) ⇒ Object
22 23 24 |
# File 'lib/madmin/field/associatable.rb', line 22 def association_id_for(resource) value_for(resource).id end |
#association_id_or_blank_for(resource) ⇒ Object
26 27 28 |
# File 'lib/madmin/field/associatable.rb', line 26 def association_id_or_blank_for(resource) value_for(resource).try(:id) end |
#association_param ⇒ Object
30 31 32 |
# File 'lib/madmin/field/associatable.rb', line 30 def association_param ActiveModel::Naming.param_key(association_class) end |
#association_slug ⇒ Object
34 35 36 |
# File 'lib/madmin/field/associatable.rb', line 34 def association_slug Object.const_get("::Madmin::Resources::#{association_class}").new.slug end |
#association_value_for(resource) ⇒ Object
38 39 40 |
# File 'lib/madmin/field/associatable.rb', line 38 def association_value_for(resource) value_for(resource).send(association_display_value) end |
#initialize(args) ⇒ Object
13 14 15 16 |
# File 'lib/madmin/field/associatable.rb', line 13 def initialize(args) super(args) implement_association! end |
#strong_params_keys ⇒ Object
42 43 44 |
# File 'lib/madmin/field/associatable.rb', line 42 def strong_params_keys [association_foreign_key] end |