Module: Ooor::NestedAttributes::ClassMethods

Defined in:
lib/ooor/nested_attributes.rb

Instance Method Summary collapse

Instance Method Details

#accepts_nested_attributes_for(*attr_names) ⇒ Object

Defines an attributes writer for the specified association(s). Note that in Ooor this is active by default for all one2many and many2one associations



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ooor/nested_attributes.rb', line 12

def accepts_nested_attributes_for(*attr_names)
  attr_names.each do |association_name|
    if rel = all_fields[association_name]
      reflection = OpenStruct.new(rel.merge({options: {autosave: true}, name: association_name})) #TODO use a reflection class
      generate_association_writer(association_name, :collection) #TODO add support for m2o
      add_autosave_association_callbacks(reflection)
    else
      raise ArgumentError, "No association found for name `#{association_name}'. Has it been defined yet?"
    end
  end
end