instance method
generate_association_writer
Ruby on Rails 4.0.13
Since v4.0.13 PrivateSignature
generate_association_writer(association_name, type)
Generates a writer method for this association. Serves as a point for accessing the objects in the association. For example, this method could generate the following:
def pirate_attributes=(attributes) assign_nested_attributes_for_one_to_one_association(:pirate, attributes) end
This redirects the attempts to write objects in an association through the helper methods defined below. Makes it seem like the nested associations are just regular associations.
Parameters
-
association_namereq -
typereq
Source
# File activerecord/lib/active_record/nested_attributes.rb, line 333
def generate_association_writer(association_name, type)
generated_feature_methods.module_eval <<-eoruby, __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
eoruby
end
Defined in activerecord/lib/active_record/nested_attributes.rb line 333
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::NestedAttributes::ClassMethods