method
form_tag
![Extensive documentation Importance_4](https://d2vfyqvduarcvs.cloudfront.net/images/importance_4.png?1349367920)
v1.1.6 -
Show latest stable
-
4 notes -
Class: ActionView::Helpers::FormTagHelper
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (13)
- 2.0.3 (1)
- 2.1.0 (-1)
- 2.2.1 (-1)
- 2.3.8 (0)
- 3.0.0 (5)
- 3.0.9 (-1)
- 3.1.0 (8)
- 3.2.1 (0)
- 3.2.8 (6)
- 3.2.13 (1)
- 4.0.2 (0)
- 4.1.8 (2)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (-37)
- 7.1.3.2 (38)
- 7.1.3.4 (0)
- What's this?
form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)
public
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".
Register or
log in
to add new notes.
sethladd -
October 2, 2009
stevo -
October 7, 2011
batasrki -
October 24, 2012
eavgerinos -
October 16, 2013
![Default_avatar_30](https://www.gravatar.com/avatar/e37b8bf60f4b94e4d9be6e32cf4fa394?size=30&default=http://apidock.com/images/default_avatar_30.png)
5 thanks
form_tag with named route and html class
<% form_tag position_user_card_path(@user, card), :method => :put, :class => ‘position-form’ do %>
![Default_avatar_30](https://www.gravatar.com/avatar/16b8d429e0123bc50ba8ad27cdaa6ff4?size=30&default=http://apidock.com/images/default_avatar_30.png)
3 thanks
How to submit current url
For example to change some kind of param on select change…
<%= form_tag({}, {:method => :get}) do %> <%= select_tag :new_locale, options_for_select(I18n.available_locales, I18n.locale), :onchange => "this.form.submit();" %> <% end %>
![Default_avatar_30](https://www.gravatar.com/avatar/25a3f4b3a1e6afc89644084d2eb00b29?size=30&default=http://apidock.com/images/default_avatar_30.png)
2 thanks
To add an ID to the form
Found this the hard way, but to add an ID to the form generated by form_tag, you must explicitly make hashes.
Add ID
<%= form_tag({:action => 'create'}, {:id => 'anID'}) %>
![Default_avatar_30](https://www.gravatar.com/avatar/2123b4f1cb2fefd2543562bfd8bcf944?size=30&default=http://apidock.com/images/default_avatar_30.png)
1 thank
Erb tags
The <% -%> is not being used since Rails 3.
The example above should be changed to:
<%= form_tag('/posts') do %> <div><%= submit_tag 'Save' %></div> <% end %>