Module: Mongoid::Attributes::ClassMethods
- Defined in:
- lib/mongoid/attributes.rb
Instance Method Summary collapse
-
#accepts_nested_attributes_for(*args) ⇒ Object
Defines attribute setters for the associations specified by the names.
Instance Method Details
#accepts_nested_attributes_for(*args) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/mongoid/attributes.rb', line 171 def accepts_nested_attributes_for(*args) associations = args.flatten = associations.last.is_a?(Hash) ? associations.pop : {} associations.each do |name| define_method("#{name}_attributes=") do |attrs| reject(attrs, ) association = send(name) if association update(association, true) association.nested_build(attrs) else send("build_#{name}", attrs) end end end end |