Search code examples
ruby-on-rails-4

How to change the button title when I use the the form to edit and update in Ruby on Rails


In the views/articles/new.html.erb I have

<div class="py-16 bg-gray-50 overflow-hidden lg:py-24">
  <div class="relative max-w-xl mx-auto px-4 sm:px-6 lg:px-8 lg:max-w-7xl">


<h1>Novo Artigo</h1>

<%= render "form", article: @article %>
  </div>
</div>

And at the views/articles/new.html.erb I have

<div class="py-16 bg-gray-50 overflow-hidden lg:py-24">
  <div class="relative max-w-xl mx-auto px-4 sm:px-6 lg:px-8 lg:max-w-7xl">

  <h1>Editar artigo</h1>

  <%= render "form", article: @article %>
  </div>
</div>

I have the _form.html.erb and I would like to know how can I change the button title when I am editing the article and when I creating a new article.

<%= form_with model: article do |form| %>
  <-- other code -->
  <%= form.submit 'Criar artigo', class:"mt-44 inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md shadow-sm text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"%>
<% end %>


Solution

  • The solution was remove the text on <%= form.submit 'Criar atigo'...%> and at the config/locales/en.yml I wrote this:

    en:
      helpers:
        submit:
          create: "Criar um artigo"
          update: "Editar um artigo"