Rod Nelson
Rod Nelson

Reputation: 3331

Rails: How to change the text on the submit button in a Rails Form

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 %>

Upvotes: 117

Views: 90729

Answers (10)

Asif Ahmed
Asif Ahmed

Reputation: 11

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

Upvotes: 1

Pulkit Agarwal
Pulkit Agarwal

Reputation: 594

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.

Upvotes: 8

arogachev
arogachev

Reputation: 33548

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.

Upvotes: 3

Cris R
Cris R

Reputation: 1398

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

Upvotes: 1

Ajey
Ajey

Reputation: 8222

Its simple, use

<%= f.submit 'Desired text on the button' %>

Upvotes: 0

Claudio Shigueo Watanabe
Claudio Shigueo Watanabe

Reputation: 1003

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

Upvotes: 5

Nathan Kot
Nathan Kot

Reputation: 2432

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.)

Upvotes: 45

daniel
daniel

Reputation: 651

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"

Upvotes: 65

tomeduarte
tomeduarte

Reputation: 2843

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:

Upvotes: 16

Andrei S
Andrei S

Reputation: 6516

instead of

<%= f.submit  %>

put

<%= f.submit "My Submit Text" %>

Upvotes: 210

Related Questions