Skip to content

Commit

Permalink
Form Helpers guide: Use new syntax for fields_for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jivey authored and mikel committed Jun 3, 2010
1 parent e09e0a0 commit 24ac08f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions railties/guides/source/form_helpers.textile
Expand Up @@ -255,7 +255,7 @@ You can create a similar binding without actually creating +<form>+ tags
<erb>
<%= form_for :person, @person, :url => { :action => "create" } do |person_form| %>
<%= person_form.text_field :name %>
<% fields_for @person.contact_detail do |contact_details_form| %>
<%= fields_for @person.contact_detail do |contact_details_form| %>
<%= contact_details_form.text_field :phone_number %>
<% end %>
<% end %>
Expand Down Expand Up @@ -697,7 +697,7 @@ You might want to render a form with a set of edit fields for each of a person's
<%= form_for @person do |person_form| %>
<%= person_form.text_field :name %>
<% for address in @person.addresses %>
<% person_form.fields_for address, :index => address do |address_form|%>
<%= person_form.fields_for address, :index => address do |address_form|%>
<%= address_form.text_field :city %>
<% end %>
<% end %>
Expand Down Expand Up @@ -725,7 +725,7 @@ Rails knows that all these inputs should be part of the person hash because you
To create more intricate nestings, you can specify the first part of the input name (+person[address]+ in the previous example) explicitly, for example

<erb>
<% fields_for 'person[address][primary]', address, :index => address do |address_form| %>
<%= fields_for 'person[address][primary]', address, :index => address do |address_form| %>
<%= address_form.text_field :city %>
<% end %>
</erb>
Expand All @@ -741,7 +741,7 @@ As a general rule the final input name is the concatenation of the name given to
As a shortcut you can append [] to the name and omit the +:index+ option. This is the same as specifying +:index => address+ so

<erb>
<% fields_for 'person[address][primary][]', address do |address_form| %>
<%= fields_for 'person[address][primary][]', address do |address_form| %>
<%= address_form.text_field :city %>
<% end %>
</erb>
Expand Down

0 comments on commit 24ac08f

Please sign in to comment.