How to replace "Update" button by "Save" and "Cancel" buttons in a Ruby on Rails application with "form_with" form helper?

196 views Asked by At

I am using a form in a rails application in order to update a record.

<%= form_with model: @article do |form| %>
  <%= form.text_field :title %>
  <%= form.text_area :body %>
  <%= form.submit %>
<% end %>

But I don't want only one "Update" button, I would like 2 buttons (Save and Cancel). How can I do that ?

1

There are 1 answers

0
Christos-Angelos Vasilopoulos On

For a Cancel button, you could use a link_to to redirect to a different page.

<%= link_to 'Cancel', preferred_redirect_path %>

To change the text for the submit you can use the following.

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