2012-02-16 17 views
0

1つのフォーム内に2つの送信ボタンを持つことはできますか?メソッドは異なるアクションにサブミットしますか?Railsのform_for内に2つの送信ボタンを置いて、別のアクションにサブミットするには?

私が最初にこのquestionを見て、このRailscastの終わりに向かってこれに答えの一つでリンク(かなり古い)railscastに続く、ライアンベイツは、異なるアクションにフォームを送信するためにsubmit_to_remoteメソッドを使用することを提案しています。私はこのsubmit_to_remoteメソッドをドキュメントで見つけることができません(私はRails 3.1を使用しています)。異なる送信ボタンを別のアクションに提出させる方法はありますか?

+0

1語... jQuery – drhenner

答えて

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(); 
}); 

}; 
関連する問題