aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/nested_model_forms.textile
diff options
context:
space:
mode:
Diffstat (limited to 'railties/guides/source/nested_model_forms.textile')
-rw-r--r--railties/guides/source/nested_model_forms.textile18
1 files changed, 9 insertions, 9 deletions
diff --git a/railties/guides/source/nested_model_forms.textile b/railties/guides/source/nested_model_forms.textile
index 39b0c32f24..55694c0eb4 100644
--- a/railties/guides/source/nested_model_forms.textile
+++ b/railties/guides/source/nested_model_forms.textile
@@ -1,6 +1,6 @@
h2. Rails nested model forms
-Creating a form for a model _and_ its associations can become quite tedious. Therefor Rails provides helpers to assist in dealing with the complexities of generating these forms _and_ the required CRUD operations to create, update, and destroy associations.
+Creating a form for a model _and_ its associations can become quite tedious. Therefore Rails provides helpers to assist in dealing with the complexities of generating these forms _and_ the required CRUD operations to create, update, and destroy associations.
In this guide you will:
@@ -63,7 +63,7 @@ class Person
def address
Address.new
end
-
+
def address_attributes=(attributes)
# ...
end
@@ -77,7 +77,7 @@ class Person
def projects
[Project.new, Project.new]
end
-
+
def projects_attributes=(attributes)
# ...
end
@@ -101,7 +101,7 @@ class PeopleController < ActionController:Base
@person.built_address
2.times { @person.projects.build }
end
-
+
def create
@person = Person.new(params[:person])
if @person.save
@@ -142,7 +142,7 @@ Now add a nested form for the +address+ association:
<erb>
<%= form_for @person do |f| %>
<%= f.text_field :name %>
-
+
<%= f.fields_for :address do |af| %>
<%= f.text_field :street %>
<% end %>
@@ -154,7 +154,7 @@ This generates:
<html>
<form action="/people" class="new_person" id="new_person" method="post">
<input id="person_name" name="person[name]" size="30" type="text" />
-
+
<input id="person_address_attributes_street" name="person[address_attributes][street]" size="30" type="text" />
</form>
</html>
@@ -183,7 +183,7 @@ The form code for an association collection is pretty similar to that of a singl
<erb>
<%= form_for @person do |f| %>
<%= f.text_field :name %>
-
+
<%= f.fields_for :projects do |pf| %>
<%= f.text_field :name %>
<% end %>
@@ -195,7 +195,7 @@ Which generates:
<html>
<form action="/people" class="new_person" id="new_person" method="post">
<input id="person_name" name="person[name]" size="30" type="text" />
-
+
<input id="person_projects_attributes_0_name" name="person[projects_attributes][0][name]" size="30" type="text" />
<input id="person_projects_attributes_1_name" name="person[projects_attributes][1][name]" size="30" type="text" />
</form>
@@ -219,4 +219,4 @@ You can basically see the +projects_attributes+ hash as an array of attribute ha
NOTE: The reason that +fields_for+ constructed a form which would result in a hash instead of an array is that it won't work for any forms nested deeper than one level deep.
-TIP: You _can_ however pass an array to the writer method generated by +accepts_nested_attributes_for+ if you're using plain Ruby or some other API access. See (TODO) for more info and example. \ No newline at end of file
+TIP: You _can_ however pass an array to the writer method generated by +accepts_nested_attributes_for+ if you're using plain Ruby or some other API access. See (TODO) for more info and example.