Reputation: 3868
I have my form tag and also i have two buttons in my form. How do i call different actions in my form on click of submit buttons.
Here is my code:
<%= form_for :attachment_metadata, :url=>{:action=>'delete_files'}, :html=>{:onsubmit=> "return confirm('Are you sure, you want to delete selected files?');",:multipart => true} do |f| %>
<table>
..........Some stuff here..........
</table>
<%= submit_tag 'Reprocess', :class =>'button' %>
<%= submit_tag 'Remove', :class =>'button' %>
<% end %>
On click of "Reprocess" i want to call different action but in same form.
How can i do this?
Please help
Thanks in advance
Upvotes: 1
Views: 168
Reputation: 2653
params[:commit]
can differentiate the actions of two submit tags.
Updated:
@action = params[:commit]
it gives @action
value as "Reprocess
" if your click the Reprocess
button and gives "Remove
" value if you click the Remove
button,
Upvotes: 1
Reputation: 540
You can have two different form and you can submit your form using jQuery. in this case you can submit a form to a specific location.
<form id="target" action="destination.html">
<input type="text" value="Hello there" />
<input type="submit" value="Go" />
</form>
<div id="other">
Trigger the handler
</div>
$('#target').submit(function() {
alert('Handler for .submit() called.');
return false;
});
Upvotes: 0
Reputation: 2385
This is covered in Railscast 38. M sure it will solve your problem. Its very simple. Whenever your have submit a form, it will send some information in params hash about the commit you have performed, i would suggest you to have a look at railscast and you will completely understand.
Upvotes: 1