Rails is not passing the “commit” button parameter

前端 未结 5 933
醉梦人生
醉梦人生 2021-02-08 05:27

Reinstalling a Rails app on a new server. Part of the app can fork in one of two directions based on the button the user selects. This part isn\'t working, and when I look at

5条回答
  •  花落未央
    2021-02-08 06:17

    I looked into something like this awhile ago, where there is inconsistency in how different browsers would pass in the value of a submit button on a form. I found the only practical solution was to have javascript in the button to set a hidden field, and use that value instead.

    Here is some of my code to differentiate between a save and exit, which goes one way, and save and continue which go another:

      <%= hidden_field_tag 'step_commit', '' %>
      
        <%=submit_tag 'Cancel', :name=>'cancel', :onclick=>"javascript:location.href='/';return false;" %>
        <%=submit_tag 'Save and Exit', :name=>'exit', :onclick=>"javascript:$('step_commit').value='exit';" %>
      
      
        <%=submit_tag 'Save and Continue', :name=>'continue', :onclick=>"javascript:$('step_commit').value='continue';" %>
      
    

提交回复
热议问题