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

Ruby on-RailsRuby on-Rails-3

Ruby on-Rails Problem Overview


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

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

instead of

<%= f.submit  %>

put

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

Solution 2 - Ruby on-Rails

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"

Solution 3 - Ruby on-Rails

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

Solution 4 - Ruby on-Rails

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:

Solution 5 - Ruby on-Rails

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.

Solution 6 - Ruby on-Rails

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

Solution 7 - Ruby on-Rails

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.

Solution 8 - Ruby on-Rails

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

Solution 9 - Ruby on-Rails

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

Solution 10 - Ruby on-Rails

Its simple, use

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRod NelsonView Question on Stackoverflow
Solution 1 - Ruby on-RailsAndrei SView Answer on Stackoverflow
Solution 2 - Ruby on-RailsdanielView Answer on Stackoverflow
Solution 3 - Ruby on-RailsNathan KotView Answer on Stackoverflow
Solution 4 - Ruby on-RailstomeduarteView Answer on Stackoverflow
Solution 5 - Ruby on-RailsPulkit AgarwalView Answer on Stackoverflow
Solution 6 - Ruby on-RailsClaudio Shigueo WatanabeView Answer on Stackoverflow
Solution 7 - Ruby on-RailsarogachevView Answer on Stackoverflow
Solution 8 - Ruby on-RailsCris RView Answer on Stackoverflow
Solution 9 - Ruby on-RailsAsif AhmedView Answer on Stackoverflow
Solution 10 - Ruby on-RailsAjeyView Answer on Stackoverflow