Module: Mongoid::NestedAttributes::ClassMethods
- Defined in:
- lib/mongoid/nested_attributes.rb
Overview
:nodoc:
Constant Summary collapse
- REJECT_ALL_BLANK_PROC =
proc { |attributes| attributes.all? { |key, value| key == '_destroy' || value.blank? } }
Instance Method Summary collapse
-
#accepts_nested_attributes_for(*args) ⇒ Object
Used when needing to update related models from a parent relation.
Instance Method Details
#accepts_nested_attributes_for(*args) ⇒ Object
Used when needing to update related models from a parent relation. Can be used on embedded or referenced relations.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mongoid/nested_attributes.rb', line 39 def accepts_nested_attributes_for(*args) = args. [:reject_if] = REJECT_ALL_BLANK_PROC if [:reject_if] == :all_blank args.each do |name| self.nested_attributes += [ "#{name}_attributes=" ] define_method("#{name}_attributes=") do |attrs| _assigning do relation = relations[name.to_s] relation.nested_builder(attrs, ).build(self) end end end end |