instance method
generate_association_writer
Ruby on Rails 6.1.7.10
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 367
def generate_association_writer(association_name, type)
generated_association_methods.module_eval <<-eoruby, __FILE__, __LINE__ + 1
silence_redefinition_of_method :#{association_name}_attributes=
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 367
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::NestedAttributes::ClassMethods