Skip to content
Browse files

Clarify importance of *_attributes= writer methods for nested fields

  • Loading branch information...
1 parent 6d96535 commit c6381657b7c9dbf38d2afad61c61ad000c190927 @christineyen christineyen committed
Showing with 12 additions and 8 deletions.
  1. +12 −8 actionpack/lib/action_view/helpers/form_helper.rb
View
20 actionpack/lib/action_view/helpers/form_helper.rb
@@ -517,6 +517,18 @@ def apply_form_for_options!(object_or_array, options) #:nodoc:
# end
# end
#
+ # Note that the <tt>projects_attributes=</tt> writer method is in fact
+ # required for fields_for to correctly identify <tt>:projects</tt> as a
+ # collection, and the correct indices to be set in the form markup.
+ #
+ # When projects is already an association on Person you can use
+ # +accepts_nested_attributes_for+ to define the writer method for you:
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :projects
+ # accepts_nested_attributes_for :projects
+ # end
+ #
# This model can now be used with a nested fields_for. The block given to
# the nested fields_for call will be repeated for each instance in the
# collection:
@@ -568,14 +580,6 @@ def apply_form_for_options!(object_or_array, options) #:nodoc:
# ...
# <% end %>
#
- # When projects is already an association on Person you can use
- # +accepts_nested_attributes_for+ to define the writer method for you:
- #
- # class Person < ActiveRecord::Base
- # has_many :projects
- # accepts_nested_attributes_for :projects
- # end
- #
# If you want to destroy any of the associated models through the
# form, you have to enable it first using the <tt>:allow_destroy</tt>
# option for +accepts_nested_attributes_for+:

0 comments on commit c638165

Please sign in to comment.
Something went wrong with that request. Please try again.