Rails: Multi-submit buttons in one Form

前端 未结 6 908
梦如初夏
梦如初夏 2020-11-29 19:07

Say I have an Article model, and in the article \'new\' view I have two buttons, \"Publish\" and \"Save Draft\".

My question is how can I know which button is clicke

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 19:42

    usually i using the suggestion given by John Topley (see answer above). another way is using JQuery /JS changing the form action attribute- upon clicking the submit button example:

    form_tag({} ,:method => 'post', :id => 'reports_action') do 
       .......
       ....... 
      submit_tag 'submit',  :onclick => "return changeAction();"
    end
    

    and then .....

    function changeAction(){
       $('#reports_action').attr('action','my_new_action');
    }   
    

提交回复
热议问题