aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorChristine Yen <cyen@christineyen.com>2011-06-15 03:15:27 -0700
committerChristine Yen <cyen@christineyen.com>2011-06-15 03:15:58 -0700
commitc6381657b7c9dbf38d2afad61c61ad000c190927 (patch)
tree0431738b5376183fd8d6ff2721663ac2d9310370 /actionpack/lib/action_view/helpers/form_helper.rb
parent6d965355244055e7bef995f1a263cb1cd2993e45 (diff)
downloadrails-c6381657b7c9dbf38d2afad61c61ad000c190927.tar.gz
rails-c6381657b7c9dbf38d2afad61c61ad000c190927.tar.bz2
rails-c6381657b7c9dbf38d2afad61c61ad000c190927.zip
Clarify importance of *_attributes= writer methods for nested fields
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 7ed949504d..c1273e0f3d 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -517,6 +517,18 @@ module ActionView
# 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 @@ module ActionView
# ...
# <% 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+: