Reputation: 141
I have a Rails' remote_form_for that basically changes a value of a field, and I want to have 3 buttons. First button is to Save the value of the field. The second button is to Save the value and then call Action1 (e.g. send an email that the field was changed). The third button is to Cancel.
The form is declared with
<% remote_form_for @post,
:url => { action => 'update_field1', :id => @post.id } do |f| %>
The first button is
<%= f.submit "Save", :disable_with => "Please Wait" %>
How do I implement the Second button? Much thanks!
Upvotes: 1
Views: 2084
Reputation: 16074
So this isn't really how submit tags work, is the problem with your question. Submit causes the form to submit, and the destination of the submit tag is controlled by the destination of the form, not by the submit button itself. So it doesn't matter what you put in the submit tag, it'll always go to the same controller action.
You can, however, control what the form does based on the submit button in that one controller action. Try something like this in your controller:
case params[:commit]
when 'Save' then do_something
when 'Send Email' then do_something && send_email
end
Each submit button will send a different commit param, and you can switch what the action does depending on that param.
Upvotes: 3