How to change the text on a rails form submit button?

_config.yml

It’s been a long while since I posted something on Rails, which is ironic given I spend a not trivial amount of time trying to grok it. So here is a simple tip that I hope will help out some poor soul, someone in the world:

So you’ve got a form set out, but you don’t want the button at the bottom to say “Update model_name” where model_name is the relevant name of your model.

How do you change it?

Simple: here’s an example I copied from the rails Form Helpers guide: - which tells us the answer: http://guides.rubyonrails.org/form_helpers.html

<%= form_for @article, url: {action: "create"}, html: {class: "nifty_form"} do |f| %>
  <%= f.text_field :title %>
  <%= f.text_area :body, size: "60x12" %>
  <%= f.submit "Custom Button" %>
<% end %>

Simply tack on a string as above. The line you want to highlight is

  <%= f.submit "Custom Button" %>

And that’s it. It is as simple as that!

Written on January 21, 2017