Obromios
Obromios

Reputation: 16383

How to change button label in a ruby on rails form_for submit button

In a ruby on rails form_for, I want to use a button to submit the form rather than a f.submit. If the form is for an existing @profile object, then the following code

<%= form_for @profile do %>
<% f.button submit: 'Change Me' %>

is rendered as button with the text 'Update Profile' instead of 'Change Me'. How do I change the button text?

Upvotes: 0

Views: 1714

Answers (2)

Petr Gazarov
Petr Gazarov

Reputation: 3821

<% f.button 'Change Me', type: 'submit' %>

Upvotes: 2

Obromios
Obromios

Reputation: 16383

The following worked

<%= form_for @profile do %>
<%= button_tag 'Change Me' %>

the reason being that the form_for helper automatically treats a button within the scope as a submit.

Upvotes: 0

Related Questions