Module: Humanoid::Attributes::ClassMethods
- Defined in:
- lib/humanoid/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
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/humanoid/attributes.rb', line 166 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 |