Module: Formable::ClassMethods
- Defined in:
- lib/app/models/concerns/formable.rb
Overview
Public: Add to class methods
Instance Method Summary collapse
-
#all_associations ⇒ Object
gather up the collections we care about and return them.
-
#allowed_param_names(filter_names = []) ⇒ Object
Return the complete list of key names that would appear in the form.
-
#field_names ⇒ Object
allow the model to filter out a name if they want to, meaning the model can return a subset of attribute names.
-
#many_to_many_associations ⇒ Object
Return a collection of many to many assocations.
Instance Method Details
#all_associations ⇒ Object
gather up the collections we care about and return them. For now, the many to many associations are the ones that need some extra help.
55 56 57 |
# File 'lib/app/models/concerns/formable.rb', line 55 def all_associations many_to_many_associations end |
#allowed_param_names(filter_names = []) ⇒ Object
Return the complete list of key names that would appear in the form.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/app/models/concerns/formable.rb', line 32 def allowed_param_names(filter_names = []) # Always filter out the mongoid reserved items filter_names += %w[created_at updated_at _type _id] associations = all_associations # filter out the relationship names so we don't have dups associations.each { |association| filter_names << association.keys.first } (field_names + associations).delete_if { |name| filter_names.include?(name) } rescue StandardError attribute_names.delete_if { |name| filter_names.include?(name) } end |
#field_names ⇒ Object
allow the model to filter out a name if they want to, meaning the model can return a subset of attribute names
47 48 49 |
# File 'lib/app/models/concerns/formable.rb', line 47 def field_names attribute_names end |
#many_to_many_associations ⇒ Object
Return a collection of many to many assocations. We basically need to turn the current value returned by attribute names
relationship_ids
to
{ relationship_ids => [] }
Telling the permit command to accept the value as an array of items.
71 72 73 74 75 76 77 78 79 |
# File 'lib/app/models/concerns/formable.rb', line 71 def many_to_many_associations associations = [] reflect_on_all_associations.each do |association| next unless association.macro == :has_and_belongs_to_many associations << { association.key => [] } end associations end |