From 92eab845a422436aaba4abc9de90f937a91c6a4e Mon Sep 17 00:00:00 2001 From: James Miller Date: Tue, 6 Apr 2010 14:27:19 -0700 Subject: [PATCH] First run of updating erb syntax for 3.0 --- railties/guides/source/form_helpers.textile | 18 +++++++++--------- railties/guides/source/getting_started.textile | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 441899ba32..050486a5a4 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -21,7 +21,7 @@ h3. Dealing with Basic Forms The most basic form helper is +form_tag+. -<% form_tag do %> +<%= form_tag do %> Form contents <% end %> @@ -59,7 +59,7 @@ To create this form you will use +form_tag+, +label_tag+, +text_field_tag+, and A basic search form -<% form_tag(search_path, :method => "get") do %> +<%= form_tag(search_path, :method => "get") do %> <%= label_tag(:q, "Search for:") %> <%= text_field_tag(:q) %> <%= submit_tag("Search") %> @@ -222,7 +222,7 @@ end The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks like this: -<% form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %> +<%= form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %> <%= f.text_field :title %> <%= f.text_area :body, :size => "60x12" %> <%= submit_tag "Create" %> @@ -253,7 +253,7 @@ The helper methods called on the form builder are identical to the model object You can create a similar binding without actually creating +<form>+ tags with the +fields_for+ helper. This is useful for editing additional model objects with the same form. For example if you had a Person model with an associated ContactDetail model you could create a form for creating both like so: -<% form_for :person, @person, :url => { :action => "create" } do |person_form| %> +<%= form_for :person, @person, :url => { :action => "create" } do |person_form| %> <%= person_form.text_field :name %> <% fields_for @person.contact_detail do |contact_details_form| %> <%= contact_details_form.text_field :phone_number %> @@ -554,11 +554,11 @@ A common task is uploading some sort of file, whether it's a picture of a person The following two forms both upload a file. -<% form_tag({:action => :upload}, :multipart => true) do %> +<%= form_tag({:action => :upload}, :multipart => true) do %> <%= file_field_tag 'picture' %> <% end %> -<% form_for @person, :html => {:multipart => true} do |f| %> +<%= form_for @person, :html => {:multipart => true} do |f| %> <%= f.file_field :picture %> <% end %> @@ -591,7 +591,7 @@ h3. Customizing Form Builders As mentioned previously the object yielded by +form_for+ and +fields_for+ is an instance of FormBuilder (or a subclass thereof). Form builders encapsulate the notion of displaying form elements for a single object. While you can of course write helpers for your forms in the usual way you can also subclass FormBuilder and add the helpers there. For example -<% form_for @person do |f| %> +<%= form_for @person do |f| %> <%= text_field_with_label f, :first_name %> <% end %> @@ -599,7 +599,7 @@ As mentioned previously the object yielded by +form_for+ and +fields_for+ is an can be replaced with -<% form_for @person, :builder => LabellingFormBuilder do |f| %> +<%= form_for @person, :builder => LabellingFormBuilder do |f| %> <%= f.text_field :first_name %> <% end %> @@ -694,7 +694,7 @@ The previous sections did not use the Rails form helpers at all. While you can c You might want to render a form with a set of edit fields for each of a person's addresses. For example: -<% form_for @person do |person_form| %> +<%= 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|%> diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 485a35c3cb..17279146a7 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -602,7 +602,7 @@ The +<%= render 'form' %>+ line is our first introduction to _partials_ in If you take a look at +views/posts/_form.html.erb+ file, you will see the following: -<% form_for(@post) do |f| %> +<%= form_for(@post) do |f| %> <%= f.error_messages %>
@@ -906,7 +906,7 @@ So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+

Add a comment:

-<% form_for([@post, @post.comments.build]) do |f| %> +<%= form_for([@post, @post.comments.build]) do |f| %> <%= f.error_messages %>
@@ -1041,7 +1041,7 @@ Then in the +app/views/posts/show.html.erb+ you can change it to look like the f :collection => @post.comments %>

Add a comment:

-<% form_for([@post, @post.comments.build]) do |f| %> +<%= form_for([@post, @post.comments.build]) do |f| %> <%= f.error_messages %>
@@ -1070,7 +1070,7 @@ h4. Rendering a Partial Form Lets also move that new comment section out to it's own partial, again, you create a file +app/views/comments/_form.html.erb+ and in it you put: -<% form_for([@post, @post.comments.build]) do |f| %> +<%= form_for([@post, @post.comments.build]) do |f| %> <%= f.error_messages %>
@@ -1278,7 +1278,7 @@ We will modify +views/posts/_form.html.erb+ to render a partial to make a tag: <% @post.tags.build %> -<% form_for(@post) do |post_form| %> +<%= form_for(@post) do |post_form| %> <%= post_form.error_messages %>
-- GitLab