Module: Her::Model::NestedAttributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- Her::Model
- Defined in:
- lib/her/model/nested_attributes.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#saved_nested_attributes ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/her/model/nested_attributes.rb', line 6 def saved_nested_attributes nested_attributes = self.class.saved_nested_associations.each_with_object({}) do |association_name, hash| if association = self.send(association_name) if association.kind_of?(Array) associates = {} association.each_with_index {|a, i| associates[i] = to_params_for_nesting(a) } hash["#{association_name}_attributes".to_sym] = associates else hash["#{association_name}_attributes".to_sym] = to_params_for_nesting(association) end end end end |
#to_params_for_nesting(associate) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/her/model/nested_attributes.rb', line 22 def to_params_for_nesting(associate) associate_params = associate.to_params associate_params = associate_params[associate.class.included_root_element] if associate.class.include_root_in_json? associate_params['_destroy'] = associate. associate_params['id'] = associate.id associate_params end |