Starts a form tag that points the action to an url configured with
url_for_options
just like ActionController::Base#url_for. The
method for the form defaults to POST.
Options
-
:multipart
- If set to true, the enctype is set to âmultipart/form-dataâ. -
:method
- The method to use when submitting the form, usually either âgetâ or âpostâ. If âpatchâ, âputâ, âdeleteâ, or another verb is used, a hidden input with name_method
is added to simulate the verb over post. -
:authenticity_token
- Authenticity token to use in the form. Use only if you need to pass custom authenticity token string, or to not add authenticity_token field at all (by passingfalse
). Remote forms may omit the embedded authenticity token by settingconfig.action_view.embed_authenticity_token_in_remote_forms = false
. This is helpful when you're fragment-caching the form. Remote forms get the authenticity token from themeta
tag, so embedding is unnecessary unless you support browsers without JavaScript. -
:remote
- If set to true, will allow the Unobtrusive JavaScript drivers to control the submit behavior. By default this behavior is an ajax submit. -
:enforce_utf8
- If set to false, a hidden input with name utf8 is not output. -
Any other key creates standard HTML attributes for the tag.
Examples
form_tag('/posts') # => <form action="/posts" method="post"> form_tag('/posts/1', method: :put) # => <form action="/posts/1" method="post"> ... <input name="_method" type="hidden" value="put" /> ... form_tag('/upload', multipart: true) # => <form action="/upload" method="post" enctype="multipart/form-data"> <%= form_tag('/posts') do -%> <div><%= submit_tag 'Save' %></div> <% end -%> # => <form action="/posts" method="post"><div><input type="submit" name="commit" value="Save" /></div></form> <%= form_tag('/posts', remote: true) %> # => <form action="/posts" method="post" data-remote="true"> form_tag('http://far.away.com/form', authenticity_token: false) # form without authenticity token form_tag('http://far.away.com/form', authenticity_token: "cf50faa3fe97702ca1ae") # form with custom authenticity token
Please login to continue.