12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/active_data/model/nested_attributes.rb', line 12
def accepts_nested_attributes_for *attr_names
attr_names.each do |association_name|
reflection = reflect_on_association association_name
type = (reflection.collection? ? :collection : :one_to_one)
class_eval <<-EOS, __FILE__, __LINE__ + 1
if method_defined?(:#{association_name}_attributes=)
remove_method(:#{association_name}_attributes=)
end
def #{association_name}_attributes=(attributes)
assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
end
EOS
end
end
|