Two submit buttons, but only one remote: true

I have a form with two submit buttons so that I can perform the following tasks:

<% form_for(something) do |f| %> .. <%= f.submit 'A' %> <%= f.submit 'B' %> .. <% end %> 

Controller:

 def <controller action> if params[:commit] == 'A' # A was pressed elsif params[:commit] == 'B' # B was pressed end end 

So my question is: how can I say that when a form is submitted using the "A" button, the form:

 <% form_for(something), :remote => true do |f| %> 

And when it is subalized with button B, its normal form is:

 <% form_for(something) do |f| %> 
0
ruby-on-rails ruby-on-rails-3
Aug 27 '13 at 22:08
source share
1 answer

You can't do that, I think. But this can be done through javascript.

Delete the deleted form form. Add a javascript callback to one of your submit buttons to submit the form via ajax. Adjust your controller accordingly.

+1
Aug 27 '13 at 10:21
source share



All Articles