ActionView::Helpers::FormBuilder
def submit(value = nil, options = {})

Description

Creates a type="submit" <input> whose value is based on the outer form's model.

Arguments

Changing a value updates the ERB and HTML.

= nil
Accepts:
  • A string: used as value as is.
  • A hash: treated as options (so the second argument, options, can be left out).
  • Omitted: value is the first of the following that exists:
    1. The helpers.submit.article.create translation (update if the record is persisted; likewise below)
    2. The helpers.submit.create translation
    3. Create followed by the model name (model_name.human), as in Create Article
options= {}
"publish"
Defaults to name="commit"; this option overrides it. nil omits name.
false
Accepts:
  • Omitted: adds data-disable-with set to the same string as value.
  • false: omits it.
  • A string: used as its value.
Rails UJS reads data-disable-with and, once the button is pressed, disables the button and changes its value to this string. In apps without Rails UJS (the default since Rails 7), this attribute does nothing.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <input>, and ones this site considers rarely used, are not listed here.

Shared by all helpers

true adds disabled="disabled"; false omits it. The same goes for every HTML attribute in Rails' list (BOOLEAN_ATTRIBUTES), such as readonly, required and autofocus: any value other than false or nil adds it as attr="attr".
{active: true, hidden: false}
A hash gives the keys whose values are not false or nil, joined with spaces. An array gives its elements joined with spaces, after removing nil, false and empty strings (including whitespace-only strings).
{disable_with: "Saving..."}
A hash adds data-* attributes, with _ in the keys converted to -. Array and hash values are converted to JSON strings.On this page, disable_with replaces the string in the automatically added data-disable-with.
{describedby: ["name_help", "name_error"], invalid: false}
Like :data, adds aria-* attributes. Array values are joined with spaces, leaving out nil and empty strings (nothing is added if none remain). For a hash value, the keys whose values are not false or nil are joined with spaces.
Any other options become HTML attributes of the <input>; those with a nil value are left out.
Context
The @article passed to the outer form. When the value argument is omitted, value is Create Article for a new record and Update Article for a persisted one.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview

Interacting with the preview updates the form submission.

Form submission

Form data

namevalue
Request body

Content-Type:


              

params


              
This site hides the CSRF token as (hidden). The real token is a long string that changes on every render.