30

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?

3 Answers 3

49

Should be:

<%= f.submit "Save" %>
4
  • 7
    I'm honestly embarrassed. Thank you.
    – stewart715
    Commented Apr 22, 2011 at 18:09
  • 1
    Also see this. Though it's the _tag variant, the options work for f. variants as well. Same for other form helpers.
    – Zabba
    Commented Apr 22, 2011 at 18:12
  • 2
    Consider using en.yml file - stackoverflow.com/questions/4769483/… Commented Mar 7, 2012 at 12:32
  • <%= f.submit :Save %> This works too :)
    – Kid
    Commented Nov 29, 2021 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?

1
  • 5
    You can do this with f.submit such as <%= f.submit "Save", class: "btn btn-primary" %>
    – Sithu
    Commented Dec 6, 2015 at 8:57
2

You can use this for rails > 6.1.0:

<%= form.submit "Custom button", class:"btn btn-primary" %>
1
  • 1
    It is also working for rails 5.2 Commented Jan 17, 2023 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.