submit_tag(value = "Save changes", options = {}) public

Creates a submit button with the text value as the caption.

Options

  • :confirm => 'question?' - If present the unobtrusive JavaScript drivers will provide a prompt with the question specified. If the user accepts, the form is processed normally, otherwise no action is taken.

  • :disabled - If true, the user will not be able to use this input.

  • :disable_with - Value of this parameter will be used as the value for a disabled version of the submit button when the form is submitted. This feature is provided by the unobtrusive JavaScript driver.

  • Any other key creates standard HTML options for the tag.

Examples

submit_tag
# => <input name="commit" type="submit" value="Save changes" />

submit_tag "Edit this article"
# => <input name="commit" type="submit" value="Edit this article" />

submit_tag "Save edits", :disabled => true
# => <input disabled="disabled" name="commit" type="submit" value="Save edits" />

submit_tag "Complete sale", :disable_with => "Please wait..."
# => <input name="commit" data-disable-with="Please wait..."
#    type="submit" value="Complete sale" />

submit_tag nil, :class => "form_submit"
# => <input class="form_submit" name="commit" type="submit" />

submit_tag "Edit", :disable_with => "Editing...", :class => "edit_button"
# => <input class="edit_button" data-disable_with="Editing..."
#    name="commit" type="submit" value="Edit" />

submit_tag "Save", :confirm => "Are you sure?"
# => <input name='commit' type='submit' value='Save'
      data-confirm="Are you sure?" />
Show source
Register or log in to add new notes.
June 7, 2012
2 thanks

:disable_with is deprecated

Or you can use this way:

<%= submit_tag "Login", data: { disable_with: "Please wait.." } %>
June 5, 2012
1 thank

:disable_with is deprecated

Since version 3.2.5 you should not use :disable_with.

Use this:

<%= submit_tag "Login", 'data-disable-with' => "Please wait.." %>
January 14, 2015
0 thanks

Have submit_tag send value as a nested resource

To have the submit_tag send it’s value within a nested resource for strong params use the name paramter.

submit_tag("Send", name: 'article[submit]')