aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-04-08 13:34:40 -0300
committerXavier Noria <fxn@hashref.com>2010-04-10 15:32:20 -0700
commit95d13cca7ba0433d9a95a20c3f28904ab6c76249 (patch)
tree407062a7528c31e33180d8995a74cb5542c868b1 /actionpack/lib/action_view/helpers/form_helper.rb
parent093ab3ec6e476f53a84eb90a3b1944c7e961f204 (diff)
downloadrails-95d13cca7ba0433d9a95a20c3f28904ab6c76249.tar.gz
rails-95d13cca7ba0433d9a95a20c3f28904ab6c76249.tar.bz2
rails-95d13cca7ba0433d9a95a20c3f28904ab6c76249.zip
form_for :as rubydoc and tidy up a bit the form_for doc
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb51
1 files changed, 19 insertions, 32 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index a3453cc47a..d2b3e2b214 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -45,8 +45,8 @@ module ActionView
#
# If you are using a partial for your form fields, you can use this shortcut:
#
- # <%= form_for :person, @person do |form| %>
- # <%= render :partial => f %>
+ # <%= form_for @person do |form| %>
+ # <%= render form %>
# <%= submit_tag 'Create' %>
# <% end %>
#
@@ -129,9 +129,8 @@ module ActionView
# Admin? : <%= f.check_box :admin %><br />
# <% end %>
#
- # There, the first argument is a symbol or string with the name of the
- # object the form is about, and also the name of the instance variable
- # the object is stored in.
+ # There, the argument is a symbol or string with the name of the
+ # object the form is about.
#
# The form builder acts as a regular form helper that somehow carries the
# model. Thus, the idea is that
@@ -142,26 +141,7 @@ module ActionView
#
# <%= text_field :person, :first_name %>
#
- # If the instance variable is not <tt>@person</tt> you can pass the actual
- # record as the second argument:
- #
- # <%= form_for :person, person do |f| %>
- # ...
- # <% end %>
- #
- # In that case you can think
- #
- # <%= f.text_field :first_name %>
- #
- # gets expanded to
- #
- # <%= text_field :person, :first_name, :object => person %>
- #
- # You can even display error messages of the wrapped model this way:
- #
- # <%= f.error_messages %>
- #
- # In any of its variants, the rightmost argument to +form_for+ is an
+ # The rightmost argument to +form_for+ is an
# optional hash of options:
#
# * <tt>:url</tt> - The URL the form is submitted to. It takes the same
@@ -177,7 +157,7 @@ module ActionView
# possible to use both the stand-alone FormHelper methods and methods
# from FormTagHelper. For example:
#
- # <%= form_for :person, @person do |f| %>
+ # <%= form_for @person do |f| %>
# First name: <%= f.text_field :first_name %>
# Last name : <%= f.text_field :last_name %>
# Biography : <%= text_area :person, :biography %>
@@ -203,7 +183,7 @@ module ActionView
#
# is equivalent to something like:
#
- # <%= form_for :post, @post, :url => post_path(@post), :html => { :method => :put, :class => "edit_post", :id => "edit_post_45" } do |f| %>
+ # <%= form_for @post, :as => :post, :url => post_path(@post), :html => { :method => :put, :class => "edit_post", :id => "edit_post_45" } do |f| %>
# ...
# <% end %>
#
@@ -213,9 +193,9 @@ module ActionView
# ...
# <% end %>
#
- # expands to
+ # is equivalent to something like:
#
- # <%= form_for :post, Post.new, :url => posts_path, :html => { :class => "new_post", :id => "new_post" } do |f| %>
+ # <%= form_for @post, :as => :post, :url => post_path(@post), :html => { :class => "new_post", :id => "new_post" } do |f| %>
# ...
# <% end %>
#
@@ -225,6 +205,13 @@ module ActionView
# ...
# <% end %>
#
+ # If you have an object that needs to be represented as a different
+ # parameter, like a Client that acts as a Person:
+ #
+ # <%= form_for(@post, :as => :client do |f| %>
+ # ...
+ # <% end %>
+ #
# And for namespaced routes, like +admin_post_url+:
#
# <%= form_for([:admin, @post]) do |f| %>
@@ -245,13 +232,13 @@ module ActionView
#
# Example:
#
- # <%= form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| %>
+ # <%= form_for(@post, :remote => true) do |f| %>
# ...
# <% end %>
#
# The HTML generated for this would be:
#
- # <form action='http://www.example.com' id='create-post' method='post' data-remote='true'>
+ # <form action='http://www.example.com' method='post' data-remote='true'>
# <div style='margin:0;padding:0;display:inline'>
# <input name='_method' type='hidden' value='put' />
# </div>
@@ -265,7 +252,7 @@ module ActionView
# custom builder. For example, let's say you made a helper to
# automatically add labels to form inputs.
#
- # <%= form_for :person, @person, :url => { :action => "create" }, :builder => LabellingFormBuilder do |f| %>
+ # <%= form_for @person, :url => { :action => "create" }, :builder => LabellingFormBuilder do |f| %>
# <%= f.text_field :first_name %>
# <%= f.text_field :last_name %>
# <%= text_area :person, :biography %>