method

submit

submit(value = nil, options = {})
public

Add the submit button for the given form. When no value is given, it checks if the object is a new resource or not to create the proper label:

<%= form_with model: @article do |f| %>
  <%= f.submit %>
<% end %>

In the example above, if @article is a new record, it will use “Create Article” as submit button label; otherwise, it uses “Update Article”.

Those labels can be customized using I18n under the helpers.submit key and using %{model} for translation interpolation:

en:
  helpers:
    submit:
      create: "Create a %{model}"
      update: "Confirm changes to %{model}"

It also searches for a key specific to the given object:

en:
  helpers:
    submit:
      article:
        create: "Add %{model}"

3Notes

Image as a submit button

bansalakhil · Mar 10, 20091 thank

use image_sugmit_tag to use an image as a submit button

About the options argument

tokland · Sep 22, 20101 thank

The options are not documented, but of course you can use the same options than submit_tag.

Note that all non-documented options are simply passed to the input tag. Amongst other things, this allows you to change the default name attribute (commit):

form.submit 'Cancel', :name => 'cancel'

That's very handy in forms with multiple submit buttons, this way the controller can easily check in the params which action was submitted.

submit button with rails javascript's onclick event handler method

anwuna · Nov 8, 2013

==== Code example <%= f.submit 'Create User', class: 'buttons', :onclick => "validate_user_form_and_submit()" %>