Ruby on rails Ajax提交问题-Rails

Ruby on rails Ajax提交问题-Rails,ruby-on-rails,ruby,ajax,braintree,Ruby On Rails,Ruby,Ajax,Braintree,我不相信我通过Rails UJS和Ajax提交braintree事务的解决方案是正确的,原因是我在提交时看到两个Ajax调用,而不是一个 例如,当关闭ajax(因此删除remote:true)时,提交表单似乎要等待一段时间才能提交付款(我相信braintree会接管提交事件) 但是当使用remote:true启用提交时,第一个调用是 Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here=", "first_name"=

我不相信我通过Rails UJS和Ajax提交braintree事务的解决方案是正确的,原因是我在提交时看到两个Ajax调用,而不是一个

例如,当关闭ajax(因此删除remote:true)时,提交表单似乎要等待一段时间才能提交付款(我相信braintree会接管提交事件)

但是当使用remote:true启用提交时,第一个调用是

Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here=", "first_name"=>"", "last_name"=>""} 
因此,我读到需要使用
onpaymentmethodreceived
回调函数等待该nonce,将该nonce附加到表单中,然后提交

braintree.setup(gon.client_token, 'dropin', {
  container: 'dropin-container',
  onPaymentMethodReceived: function (paymentMethod) {
   $('#braintree-transaction-form').append("<input id='p_nonce' type='hidden' name='payment_method_nonce' value='" + paymentMethod.nonce + "'></input>");
   $("#braintree-transaction-form input[type='submit']").submit();
  }
});
(二)

唯一的问题是我的控制器里有这个,我认为它不正确

def create
  nonce = params[:payment_method_nonce]
  render action: :new and return unless nonce # Is this the way to wait for the nonce
  @result = Braintree::Transaction.sale(
              amount: 2500,
              payment_method_nonce: nonce,
              customer: {
                first_name: params[:first_name],
                last_name: params[:last_name]
             }
            )
end
我想我关心的是两个电话和我的控制器代码

有没有人有过使用Braintree和Rails进行Ajax调用的经验

谢谢

充分披露:我在Braintree工作。如果您有任何进一步的问题,请随时联系

您可能会遇到提交按钮的默认行为问题,即。然而,这里没有什么可以认为这是问题所在。很可能是您的设置中的其他地方存在问题。我真的建议联系您的完整代码示例,帮助他们解决您的问题

Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here=", "first_name"=>"", "last_name"=>""}
Parameters: {"utf8"=>"✓", "authenticity_token"=>"token_here", "first_name"=>"", "last_name"=>"", "payment_method_nonce"=>"nonce_here_populated"}
def create
  nonce = params[:payment_method_nonce]
  render action: :new and return unless nonce # Is this the way to wait for the nonce
  @result = Braintree::Transaction.sale(
              amount: 2500,
              payment_method_nonce: nonce,
              customer: {
                first_name: params[:first_name],
                last_name: params[:last_name]
             }
            )
end