diff options
author | James Miller <james@jk-tech.com> | 2010-04-06 16:52:39 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-04-09 04:45:02 -0700 |
commit | 4f0982db91f4e67b36aec7f1e7445655e7bce8ce (patch) | |
tree | 638141f5a28395617296a86ac52b4dca3aca600c /railties/guides | |
parent | 42d3764b3ddc67ac5818deff06b7dfbcdd95e834 (diff) | |
download | rails-4f0982db91f4e67b36aec7f1e7445655e7bce8ce.tar.gz rails-4f0982db91f4e67b36aec7f1e7445655e7bce8ce.tar.bz2 rails-4f0982db91f4e67b36aec7f1e7445655e7bce8ce.zip |
More on the new ERB syntax in the guides
Diffstat (limited to 'railties/guides')
7 files changed, 25 insertions, 25 deletions
diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index e193c57935..caa7646b7f 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -255,12 +255,12 @@ The +destroy+ action redirects to the application's +root_url+, where the messag <html> <!-- <head/> --> <body> - <% if flash[:notice] -%> + <% if flash[:notice] %> <p class="notice"><%= flash[:notice] %></p> - <% end -%> - <% if flash[:error] -%> + <% end %> + <% if flash[:error] %> <p class="error"><%= flash[:error] %></p> - <% end -%> + <% end %> <!-- more content --> </body> </html> @@ -494,7 +494,7 @@ If you generate a form like this: <ruby> <%= form_for @user do |f| %> <%= f.text_field :username %> - <%= f.text_field :password -%> + <%= f.text_field :password %> <% end %> </ruby> diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index df8cf4dc29..43ebe87875 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -135,7 +135,7 @@ The +post+ partial wraps the post's +body+ in a +div+ with the +id+ of the post *posts/_post.html.erb* <ruby> -<% div_for(post) do %> +<%= div_for(post) do %> <p><%= post.body %></p> <% end %> </ruby> @@ -158,7 +158,7 @@ You can also render a block of code within a partial layout instead of calling + <ruby> <% render(:layout => 'box', :locals => {:post => @post}) do %> - <% div_for(post) do %> + <%= div_for(post) do %> <p><%= post.body %></p> <% end %> <% end %> @@ -654,7 +654,7 @@ The core method of this helper, form_for, gives you the ability to create a form <ruby> # Note: a @person variable will have been created in the controller (e.g. @person = Person.new) -<% form_for :person, @person, :url => { :action => "create" } do |f| %> +<%= form_for :person, @person, :url => { :action => "create" } do |f| %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= submit_tag 'Create' %> @@ -695,7 +695,7 @@ h5. fields_for Creates a scope around a specific model object like form_for, but doesnât create the form tags themselves. This makes fields_for suitable for specifying additional model objects in the same form: <ruby> -<% form_for @person, :url => { :action => "update" } do |person_form| %> +<%= form_for @person, :url => { :action => "update" } do |person_form| %> First name: <%= person_form.text_field :first_name %> Last name : <%= person_form.text_field :last_name %> @@ -719,7 +719,7 @@ h5. form_for Creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields. <ruby> -<% form_for @post do |f| %> +<%= form_for @post do |f| %> <%= f.label :title, 'Title' %>: <%= f.text_field :title %><br /> <%= f.label :body, 'Body' %>: @@ -957,7 +957,7 @@ h5. field_set_tag Creates a field set for grouping HTML form elements. <ruby> -<% field_set_tag do %> +<%= field_set_tag do %> <p><%= text_field_tag 'name' %></p> <% end %> # => <fieldset><p><input id="name" name="name" type="text" /></p></fieldset> @@ -970,10 +970,10 @@ Creates a file upload field. If you are using file uploads then you will also need to set the multipart option for the form tag: <ruby> -<%= form_tag { :action => "post" }, { :multipart => true } %> +<%= form_tag { :action => "post" }, { :multipart => true } do %> <label for="file">File to Upload</label> <%= file_field_tag "file" %> <%= submit_tag %> -<%= end_form_tag %> +<% end %> </ruby> Example output: @@ -988,9 +988,9 @@ h5. form_tag Starts a form tag that points the action to an url configured with +url_for_options+ just like +ActionController::Base#url_for+. <ruby> -<% form_tag '/posts' do -%> +<%= form_tag '/posts' do %> <div><%= submit_tag 'Save' %></div> -<% end -%> +<% end %> # => <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form> </ruby> @@ -1251,7 +1251,7 @@ h5. remote_form_for Creates a form that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement and a scope around a specific resource that is used as a base for questioning about values for the fields. <ruby> -<% remote_form_for(@post) do |f| %> +<%= remote_form_for(@post) do |f| %> ... <% end %> </ruby> diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile index 6575612bee..126a6efff5 100644 --- a/railties/guides/source/activerecord_validations_callbacks.textile +++ b/railties/guides/source/activerecord_validations_callbacks.textile @@ -712,7 +712,7 @@ end </ruby> <erb> -<% form_for(@product) do |f| %> +<%= form_for(@product) do |f| %> <%= f.error_messages %> <p> <%= f.label :description %><br /> diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 17279146a7..2bbb4dc252 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -974,7 +974,7 @@ Once we have made the new comment, we send the user back to the +post_path(@post <% end %> <h2>Add a comment:</h2> -<% form_for([@post, @post.comments.build]) do |f| %> +<%= form_for([@post, @post.comments.build]) do |f| %> <%= f.error_messages %> <div class="field"> diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index fad687466e..92b36ab3e4 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -1037,7 +1037,7 @@ You can also pass local variables into partials, making them even more powerful * +_form.html.erb+ <erb> -<% form_for(zone) do |f| %> +<%= form_for(zone) do |f| %> <p> <b>Zone name</b><br /> <%= f.text_field :name %> @@ -1181,11 +1181,11 @@ On pages generated by +NewsController+, you want to hide the top menu and add a <% content_for :stylesheets do %> #top_menu {display: none} #right_menu {float: right; background-color: yellow; color: black} -<% end -%> +<% end %> <% content_for :content do %> <div id="right_menu">Right menu items here</div> <%= yield(:news_content) or yield %> -<% end -%> +<% end %> <%= render :file => 'layouts/application' %> </erb> diff --git a/railties/guides/source/nested_model_forms.textile b/railties/guides/source/nested_model_forms.textile index 4b685b214e..4a79902232 100644 --- a/railties/guides/source/nested_model_forms.textile +++ b/railties/guides/source/nested_model_forms.textile @@ -122,7 +122,7 @@ h5. Standard form Start out with a regular RESTful form: <erb> -<% form_for @person do |f| %> +<%= form_for @person do |f| %> <%= f.text_field :name %> <% end %> </erb> @@ -140,7 +140,7 @@ h5. Nested form for a single associated object Now add a nested form for the +address+ association: <erb> -<% form_for @person do |f| %> +<%= form_for @person do |f| %> <%= f.text_field :name %> <% f.fields_for :address do |af| %> @@ -181,7 +181,7 @@ h5. Nested form for a collection of associated objects The form code for an association collection is pretty similar to that of a single associated object: <erb> -<% form_for @person do |f| %> +<%= form_for @person do |f| %> <%= f.text_field :name %> <% f.fields_for :projects do |pf| %> diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index b291b541ba..6e25515fed 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -84,7 +84,7 @@ h5. ERb'in It Up ERb allows you embed ruby code within templates. Both the YAML and CSV fixture formats are pre-processed with ERb when you load fixtures. This allows you to use Ruby to help you generate some sample data. <erb> -<% earth_size = 20 -%> +<% earth_size = 20 %> mercury: size: <%= earth_size / 50 %> brightest_on: <%= 113.days.ago.to_s(:db) %> |