0

How can one have two submit buttons within one form_for method submit to different actions?

I first saw this question and followed a link in one of the answers to this (rather old) railscast Towards the end of this Railscast, Ryan Bates suggests using the submit_to_remote method to submit the form to that different action. I can't find this submit_to_remote method in the documenation (I'm using Rails 3.1). Is there still a way to have different submit buttons submit to different actions?

Community
  • 1
  • 1
John
  • 13,125
  • 14
  • 52
  • 73

1 Answers1

0
 var Widgets = window.Widgets || { };
 Widgets.orders = {
    initialize      : function( ) {
        jQuery('#sumbit1').live('click', function(){
          Widgets.orders.submitOne();
        });
        jQuery('#sumbit2').live('click', function(){
          Widgets.orders.submitTwo();
        });
    },

    submitOne :function(num) {
        jQuery.ajax({
          type : "POST",
          url: "/widgets/orders" ,
          data: jQuery('#order_form').serialize(),
          success: function(htmlText){
            if (htmlText.status > 399) {
              alert('OH NO!!!  Something went wrong!!');
            } else {
              jQuery('#orders').html(htmlText);
            }
          },
          dataType: 'html'
        });
    },
    submitTwo :function(num) {
        jQuery.ajax({
          type : "POST",
          url: "/blah/orders" ,
          data: jQuery('#order_form').serialize(),
          success: function(htmlText){
            if (htmlText.status > 399) {
              alert('OH NO!!!  Something went wrong!!');
            } else {
              jQuery('#orders').html(htmlText);
            }
          },
          dataType: 'html'
        });
    }

// Start it up
jQuery(function() {
  Widgets.orders.initialize();
});

};
drhenner
  • 2,200
  • 18
  • 23