Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Form with two submits
4 Posts
Form with two submits

I have been unable to get this to work. I want to have my edit from have a Save and Cancel button. I have the Save working just fine but I have been unable to figure out how to have another submit button and just reload the values in the form.

{ :action => 'save_edit' } do |f| %>

... error_messages and all my fields ...

You want the reset button:


I generally use the "with_action plugin":http://github.com/collectiveidea/with_action/tree/master for having two submit buttons. It allows a simple mechanism for handling different actions based on different submit buttons. There's an example on the github page.

Thank you for the replies. The first solution using input with reset works until you actually post. The problem is that what if the user input did not validate, it bounces back with the validation messages. However, resetting the form does not work because the form now has the bad values from the post.

I want to support the user's decision to just bailout and reload all the data as it originally looked in case they don't want to or don't know how to fix their input mistakes. I appreciate the plugin suggestion but it seemed that this should be solvable without having to go get a plugin.

I finally figured out what had been alluding me.

f.sumit 'Cancel', :name => 'cancel_button'

Then in the code I just look for the existence of params[:cancel_button]. This seems straight forward to me but if anyone has a cleaner solution I am all ears.

4 Posts
Login to add your message