Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: How to have multiple submit buttons going to different methods (maybe with with_action?) [duplicate]

So..

<%= submit_tag 'Save', :name => 'save' %>
<%= submit_tag 'Save to Library', :name => 'library' %>

then in my controller:

with_action do |a|
    a.save do

    end

    a.library do

    end
end

the problem is that only one of the actions is getting invoked... the same one for both submit_tags... any idea why?

or how I can get two buttons to submit a form to two different methods?

like image 552
NullVoxPopuli Avatar asked Jun 21 '10 16:06

NullVoxPopuli


1 Answers

The submit button name attribute is passed to the controller as params[:commit]. So in your case:

if params[:commit] == "save"
end
like image 57
Tanel Suurhans Avatar answered Oct 12 '22 23:10

Tanel Suurhans