117

i have listed my _form.html.erb file below what i would like to do is change the text on the submit button i know how to do it in html but not shure how to do it in Rails 3

%= form_for(@faq) do |f| %>
  <% if @faq.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@faq.errors.count, "error") %> prohibited this faq from being saved:</h2>

      <ul>
      <% @faq.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :question %><br />
    <%= f.text_field :question %>
  </div>
  <div class="field">
    <%= f.label :answer %><br />
    <%= f.text_area :answer %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Rod Nelson
  • 3,301
  • 5
  • 22
  • 25

10 Answers10

208

instead of

<%= f.submit  %>

put

<%= f.submit "My Submit Text" %>
Andrei S
  • 6,486
  • 5
  • 37
  • 54
  • OMG i cant believe i was so dang close i was trying to use it like HTML name="My Submit Text" thanks this got me what i was looking for :) – Rod Nelson Jan 22 '11 at 17:56
  • 1
    I can't believe this very simple thing isn't in the fricking [API docs for this method](http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-submit). – Grant Birchmeier Mar 15 '13 at 18:14
  • 4
    This didn't work for me -- I had to do `<%= f.submit :value => "Login" %>` instead. (Rails 3.2.11) – cassi.lup Mar 20 '13 at 10:56
  • 2
    If you want to keep the button style, you can do: f.button :submit, "My Submit Text" – jonathanrz Oct 17 '13 at 18:17
  • It's worth reading the other answers that show how to make changes using a file such as `config/locales/en.yml` – cwd Jun 16 '18 at 11:48
65

If you want to change all create and update form submit tags, this change is easy to make. Modify config/locales/en.yml like so:

en:
  helpers:
    submit:
      create: "Crear un %{model}"
      update: "Confirmar cambios al %{model} creado"
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
daniel
  • 651
  • 5
  • 2
45

Building on @daniel's answer, you can also customize submit tag values on a per-model basis:

en:
  helpers:
    submit:
      model_name:
        create: "Create"
        update: "Update"

And then in your form you can just use:

<%= f.submit %>

See here for the documentation (second example.)

Nathan Kot
  • 2,392
  • 1
  • 21
  • 31
16

You can use:

<%= f.submit 'Name of the submit button' %>

For questions like this, consider using the available docs either at

Sometimes, a google search like the one below helps:

tomeduarte
  • 2,803
  • 1
  • 17
  • 10
8

When writing in erb

<%= f.submit "your text" %>

when writing in HAML

= f.button :submit, "your text"

In HAML comma should be there after submit otherwise it will throw error.

Pulkit Agarwal
  • 594
  • 1
  • 9
  • 22
5

I had this problem and I only had to translate the model name this way:

pt-br:
  activerecord:
    models:
      user:
        one: "Usuário"
        more: "Usuários"

This also would complement @daniel's answer which gave me the hint what was missing. However, I suppose that @daniel's answer is not really necessary as it is already on rails-i18n

3

Sometimes using helpers is not acceptable because of used text or you need additionally add class etc., so you can directly override value:

<%= f.submit class: 'btn btn-primary', value: 'Login' %>

or:

<%= f.button :submit, class: 'btn btn-primary', value: 'Login' %>

By the way it was mentioned by @cassi.lup in comment to accepted answer.

Tested on Rails 4.2.3.

arogachev
  • 33,150
  • 7
  • 114
  • 117
1

Just in case, I was trying with this scenario:

f.submit t('conf.begin') class: 'btn btn-outline btn-success'

But it was not working, the solution was with a comma before the class (it was not obvious at the begining for me):

f.submit t('conf.begin'), class: 'btn btn-outline btn-success'

Cheers

Cris R
  • 1,339
  • 15
  • 27
1

for Slim version use value="xyz" to change the default submit input text.

Asif Ahmed
  • 11
  • 2
0

Its simple, use

<%= f.submit 'Desired text on the button' %>
Ajey
  • 7,924
  • 12
  • 62
  • 86