29

Any way to change the default text for a submit button?

For example, the following submit button for the user model and the update action will have a button value of Update User

<%= f.submit %>

Is there something I can add to the tag to make it, Save, for example?

Or am I going to have to do this with jQuery?

stewart715
  • 5,557
  • 11
  • 47
  • 80

3 Answers3

49

Should be:

<%= f.submit "Save" %>
Zepplock
  • 28,655
  • 4
  • 35
  • 50
  • 7
    I'm honestly embarrassed. Thank you. – stewart715 Apr 22 '11 at 18:09
  • 1
    [Also see this](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-submit_tag). Though it's the `_tag` variant, the options work for `f.` variants as well. Same for other form helpers. – Zabba Apr 22 '11 at 18:12
  • 2
    Consider using en.yml file - http://stackoverflow.com/questions/4769483/rails-3-form-how-to-change-the-text-on-the-submit-button – RidingTheRails Mar 07 '12 at 12:32
  • ```<%= f.submit :Save %>``` This works too :) – Kid Nov 29 '21 at 12:10
5

I came across this thread looking for a way to change the value for f.button :submit, not f.submit. The reason I'm using f.button :submit is because I'm using bootstrap to style the button, and the class: "btn btn-primary" argument needs to be passed to the .button method. Anyways, I couldn't find any documentation on it, so I messed around a bit and found the solution.

At first I tried <%= f.button :submit, "Create", class: "btn btn-primary" %> but it gave me an error saying I was passing 3 arguments when there should only be 2, which is what I expected.

So here's what solved the problem:

<%= f.button :submit => "", class: "btn btn-primary" %>

This made the button text what I wanted "Create Article". Before, when I just had f.button :submit, the button text was "submit", which I'm guessing was pulled from the symbol and converted into a string. Can anyone explain why passing an empty hash value did the trick?

Eli
  • 299
  • 5
  • 18
  • 5
    You can do this with `f.submit` such as `<%= f.submit "Save", class: "btn btn-primary" %>` – Sithu Dec 06 '15 at 08:57
2

You can use this for rails > 6.1.0:

<%= form.submit "Custom button", class:"btn btn-primary" %>
antoniolulee
  • 990
  • 6
  • 6