method

submit_tag

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

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

Options

  • :data - This option can be used to add custom data attributes.

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

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

Examples

submit_tag
# => <input name="commit" data-disable-with="Save changes" type="submit" value="Save changes" />

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

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

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

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

3Notes

:disable_with is deprecated

carlosbrando · Jun 7, 20122 thanks

Or you can use this way:

<%= submit_tag "Login", data: { disable_with: "Please wait.." } %>

:disable_with is deprecated

boblin · Jun 5, 20121 thank

Since version 3.2.5 you should not use :disable_with.

Use this: <%= submit_tag "Login", 'data-disable-with' => "Please wait.." %>

Have submit_tag send value as a nested resource

danielpclark · Jan 14, 2015

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]')