Ruby on Rails: How to have multiple submit buttons

2019-01-18 05:08发布

This question already has an answer here:

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?

1条回答
手持菜刀,她持情操
2楼-- · 2019-01-18 05:40

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

if params[:commit] == "save"
end
查看更多
登录 后发表回答