instance method generate_association_writer

Ruby on Rails edge

Since v4.0.13 Private — implementation detail, not part of the public API

Available in: v4.0.13 v4.1.16 v4.2.11.3 v5.0.7.2 v5.1.7 v5.2.8.1 v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.4 v8.0.5.1 v8.1.4 edge

Signature

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_name req
type req
Source
# File activerecord/lib/active_record/nested_attributes.rb, line 434
        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)
              association = association(:#{association_name})
              deprecated_associations_api_guard(association, :#{association_name}_attributes=)
              assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
            end
          eoruby
        end

Defined in activerecord/lib/active_record/nested_attributes.rb line 434 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::NestedAttributes::ClassMethods

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close