Can I have a button in side the form, but do not have the type=submit?
I am doing something special. I have a form,
<%= form_for(@user) do |f| %>
and this form will be rendered based on a value in a session.
In side the form, I have f.submit already and I want to have another button, cancel button, to invoke a method from controller to change the session value if user want to cancel the input.
But if I use button_to, the type of the button will be “submit”, when I click on the button, it will submit the whole form. If some of the value are not valid, it will complain. It does not work as the “cancel” button that I expected.
So can I have a button that does not submit the form?
I tried to use submit_tag, but the buttom dosn`t work for me…
<%= submit_tag 'Cancel Edit', :type => 'button', :controller => 'my_account', :action=>'cancel_edit' %>
The
button_tohelper actually generates a whole form:So that’s definitely not what you want. I think you just want to generate a simple
<input type="button">element in your HTML. However, there is nobutton_taginFormTagHelperbut there is asubmit_tagthat you can hand a:typeoption to and that will:So try this:
where “Pancakes” would be your real label.