开发者

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

开发者 https://www.devze.com 2023-01-04 17:49 出处:网络
This question already has answers here: How do I c开发者_高级运维reate multiple submit buttons for the same form in Rails?
This question already has answers here: How do I c开发者_高级运维reate multiple submit buttons for the same form in Rails? (7 answers) Closed 9 years ago.

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?


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

if params[:commit] == "save"
end
0

精彩评论

暂无评论...
验证码 换一张
取 消