Module: Her::Model::NestedAttributes::ClassMethods
- Defined in:
- lib/her/model/nested_attributes.rb
Instance Method Summary collapse
-
#accepts_nested_attributes_for(*associations) ⇒ Object
Allow nested attributes for an association.
- #saved_nested_associations ⇒ Object
- #sends_nested_attributes_for(*associations) ⇒ Object
Instance Method Details
#accepts_nested_attributes_for(*associations) ⇒ Object
Allow nested attributes for an association
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/her/model/nested_attributes.rb', line 48 def accepts_nested_attributes_for(*associations) allowed_association_names = association_names associations.each do |association_name| unless allowed_association_names.include?(association_name) raise Her::Errors::AssociationUnknownError.new("Unknown association name :#{association_name} in accepts_nested_attributes_for") end class_eval <<-RUBY, __FILE__, __LINE__ + 1 if method_defined?(:#{association_name}_attributes=) remove_method(:#{association_name}_attributes=) end def #{association_name}_attributes=(attributes) self.#{association_name}.assign_nested_attributes(attributes) end RUBY end end |
#saved_nested_associations ⇒ Object
68 69 70 |
# File 'lib/her/model/nested_attributes.rb', line 68 def saved_nested_associations @_her_saved_associations ||= [] end |
#sends_nested_attributes_for(*associations) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/her/model/nested_attributes.rb', line 72 def sends_nested_attributes_for(*associations) allowed_association_names = association_names associations.each do |association_name| unless allowed_association_names.include?(association_name) raise Her::Errors::AssociationUnknownError.new("Unknown association name :#{association_name} in sends_nested_attributes_for") end saved_nested_associations.push association_name end end |