Skip to content
This repository
Browse code

First run of updating erb syntax for 3.0

  • Loading branch information...
commit 92eab845a422436aaba4abc9de90f937a91c6a4e 1 parent 80e7178
James Miller authored April 06, 2010
18  railties/guides/source/form_helpers.textile
Source Rendered
@@ -21,7 +21,7 @@ h3. Dealing with Basic Forms
21 21
 The most basic form helper is +form_tag+.
22 22
 
23 23
 <erb>
24  
-<% form_tag do %>
  24
+<%= form_tag do %>
25 25
   Form contents
26 26
 <% end %>
27 27
 </erb>
@@ -59,7 +59,7 @@ To create this form you will use +form_tag+, +label_tag+, +text_field_tag+, and
59 59
 A basic search form
60 60
 
61 61
 <html>
62  
-<% form_tag(search_path, :method => "get") do %>
  62
+<%= form_tag(search_path, :method => "get") do %>
63 63
   <%= label_tag(:q, "Search for:") %>
64 64
   <%= text_field_tag(:q) %>
65 65
   <%= submit_tag("Search") %>
@@ -222,7 +222,7 @@ end
222 222
 The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks like this:
223 223
 
224 224
 <erb>
225  
-<% form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>
  225
+<%= form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>
226 226
   <%= f.text_field :title %>
227 227
   <%= f.text_area :body, :size => "60x12" %>
228 228
   <%= submit_tag "Create" %>
@@ -253,7 +253,7 @@ The helper methods called on the form builder are identical to the model object
253 253
 You can create a similar binding without actually creating  +&lt;form&gt;+ 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:
254 254
 
255 255
 <erb>
256  
-<% form_for :person, @person, :url => { :action => "create" } do |person_form| %>
  256
+<%= form_for :person, @person, :url => { :action => "create" } do |person_form| %>
257 257
   <%= person_form.text_field :name %>
258 258
   <% fields_for @person.contact_detail do |contact_details_form| %>
259 259
     <%= 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
554 554
 The following two forms both upload a file.
555 555
 
556 556
 <erb>
557  
-<% form_tag({:action => :upload}, :multipart => true) do %>
  557
+<%= form_tag({:action => :upload}, :multipart => true) do %>
558 558
   <%= file_field_tag 'picture' %>
559 559
 <% end %>
560 560
 
561  
-<% form_for @person, :html => {:multipart => true} do |f| %>
  561
+<%= form_for @person, :html => {:multipart => true} do |f| %>
562 562
   <%= f.file_field :picture %>
563 563
 <% end %>
564 564
 </erb>
@@ -591,7 +591,7 @@ h3. Customizing Form Builders
591 591
 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
592 592
 
593 593
 <erb>
594  
-<% form_for @person do |f| %>
  594
+<%= form_for @person do |f| %>
595 595
   <%= text_field_with_label f, :first_name %>
596 596
 <% end %>
597 597
 </erb>
@@ -599,7 +599,7 @@ As mentioned previously the object yielded by +form_for+ and +fields_for+ is an
599 599
 can be replaced with
600 600
 
601 601
 <erb>
602  
-<% form_for @person, :builder => LabellingFormBuilder do |f| %>
  602
+<%= form_for @person, :builder => LabellingFormBuilder do |f| %>
603 603
   <%= f.text_field :first_name %>
604 604
 <% end %>
605 605
 </erb>
@@ -694,7 +694,7 @@ The previous sections did not use the Rails form helpers at all. While you can c
694 694
 You might want to render a form with a set of edit fields for each of a person's addresses. For example:
695 695
 
696 696
 <erb>
697  
-<% form_for @person do |person_form| %>
  697
+<%= form_for @person do |person_form| %>
698 698
   <%= person_form.text_field :name %>
699 699
   <% for address in @person.addresses %>
700 700
     <% person_form.fields_for address, :index => address do |address_form|%>
10  railties/guides/source/getting_started.textile
Source Rendered
@@ -602,7 +602,7 @@ The +&lt;%= render 'form' %&gt;+ line is our first introduction to _partials_ in
602 602
 If you take a look at +views/posts/_form.html.erb+ file, you will see the following:
603 603
 
604 604
 <erb>
605  
-<% form_for(@post) do |f| %>
  605
+<%= form_for(@post) do |f| %>
606 606
   <%= f.error_messages %>
607 607
 
608 608
   <div class="field">
@@ -906,7 +906,7 @@ So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+
906 906
 </p>
907 907
 
908 908
 <h2>Add a comment:</h2>
909  
-<% form_for([@post, @post.comments.build]) do |f| %>
  909
+<%= form_for([@post, @post.comments.build]) do |f| %>
910 910
   <%= f.error_messages %>
911 911
 
912 912
   <div class="field">
@@ -1041,7 +1041,7 @@ Then in the +app/views/posts/show.html.erb+ you can change it to look like the f
1041 1041
            :collection => @post.comments %>
1042 1042
 
1043 1043
 <h2>Add a comment:</h2>
1044  
-<% form_for([@post, @post.comments.build]) do |f| %>
  1044
+<%= form_for([@post, @post.comments.build]) do |f| %>
1045 1045
   <%= f.error_messages %>
1046 1046
 
1047 1047
   <div class="field">
@@ -1070,7 +1070,7 @@ h4. Rendering a Partial Form
1070 1070
 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:
1071 1071
 
1072 1072
 <erb>
1073  
-<% form_for([@post, @post.comments.build]) do |f| %>
  1073
+<%= form_for([@post, @post.comments.build]) do |f| %>
1074 1074
   <%= f.error_messages %>
1075 1075
 
1076 1076
   <div class="field">
@@ -1278,7 +1278,7 @@ We will modify +views/posts/_form.html.erb+ to render a partial to make a tag:
1278 1278
 
1279 1279
 <erb>
1280 1280
 <% @post.tags.build %>
1281  
-<% form_for(@post) do |post_form| %>
  1281
+<%= form_for(@post) do |post_form| %>
1282 1282
   <%= post_form.error_messages %>
1283 1283
 
1284 1284
   <div class="field">

0 notes on commit 92eab84

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