diff options
author | Xavier Noria <fxn@hashref.com> | 2010-09-23 22:35:08 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-09-23 22:35:08 +0200 |
commit | 8c0c815ba711c439cbc4d295c423d5d6ab0bb848 (patch) | |
tree | 46ebc98a50a631a8962cb48505f75454cd8f24f1 /railties/guides/source/form_helpers.textile | |
parent | afdf86e8ee7c64915515e7ad8930efd858fceb43 (diff) | |
parent | 5965219ca2230dc46cff2feace19d83b7493f440 (diff) | |
download | rails-8c0c815ba711c439cbc4d295c423d5d6ab0bb848.tar.gz rails-8c0c815ba711c439cbc4d295c423d5d6ab0bb848.tar.bz2 rails-8c0c815ba711c439cbc4d295c423d5d6ab0bb848.zip |
resolves rdoc conflict
Diffstat (limited to 'railties/guides/source/form_helpers.textile')
-rw-r--r-- | railties/guides/source/form_helpers.textile | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index eb2bbc4ee9..e3b9d745b2 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -222,7 +222,7 @@ end The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks like this: <erb> -<%= form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %> +<%= form_for @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: <erb> -<%= form_for :person, @person, :url => { :action => "create" } do |person_form| %> +<%= form_for @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 %> @@ -549,7 +549,7 @@ will produce the same output if the current year is 2009 and the value chosen by h3. Uploading Files -A common task is uploading some sort of file, whether it's a picture of a person or a CSV file containing data to process. The most important thing to remember with file uploads is that the form's encoding *MUST* be set to "multipart/form-data". If you're using +form_for+ just using +file_field+ inside of it does the trick, but if you're using +form_tag+ +:multi_part => true+ must passed as an HTML option, in the second options hash. If you forget to do this the file will not be uploaded. +A common task is uploading some sort of file, whether it's a picture of a person or a CSV file containing data to process. The most important thing to remember with file uploads is that the rendered form's encoding *MUST* be set to "multipart/form-data". If you use +form_for+, this is done automatically. If you use +form_tag+, you must set it yourself, as per the following example. The following two forms both upload a file. @@ -563,6 +563,8 @@ The following two forms both upload a file. <% end %> </erb> +NOTE: Since Rails 3.1, forms rendered using +form_for+ have their encoding set to <tt>multipart/form-data</tt> automatically once a +file_field+ is used inside the block. Previous versions required you to set this explicitly. + Rails provides the usual pair of helpers: the barebones +file_field_tag+ and the model oriented +file_field+. The only difference with other helpers is that you cannot set a default value for file inputs as this would have no meaning. As you would expect in the first case the uploaded file is in +params[:picture]+ and in the second case in +params[:person][:picture]+. h4. What Gets Uploaded |