Javascript Braintree插件UI需要重新加载才能正常工作
我刚刚开始使用Braintree插件UI。客户端是javascript,服务器端是RubyonRails 我的系统现在非常简单。向用户提供与其相关的发票列表。当发票尚未支付时,他们可以单击“支付”,并进入一个新页面,其中包括Braintree下拉式UI。我的问题是:当用户被带到“支付”页面时,用户界面中的下拉菜单不会出现。如果用户重新加载页面,则会显示下拉式UI 为什么? 这里有一些相关的代码。这是相当香草味的,还没有做好,只是粗制滥造而已 来自发票/index.html.erbJavascript Braintree插件UI需要重新加载才能正常工作,javascript,ruby-on-rails,ruby,braintree,Javascript,Ruby On Rails,Ruby,Braintree,我刚刚开始使用Braintree插件UI。客户端是javascript,服务器端是RubyonRails 我的系统现在非常简单。向用户提供与其相关的发票列表。当发票尚未支付时,他们可以单击“支付”,并进入一个新页面,其中包括Braintree下拉式UI。我的问题是:当用户被带到“支付”页面时,用户界面中的下拉菜单不会出现。如果用户重新加载页面,则会显示下拉式UI 为什么? 这里有一些相关的代码。这是相当香草味的,还没有做好,只是粗制滥造而已 来自发票/index.html.erb <td&
<td>
<% if invoice.paid %>
<%= 'Paid' %>
<% else %>
<%= link_to 'Pay', payment_path(invoice.id) %>
<% end %>
</td>
来自支付和控制方:
class PaymentsController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :set_invoice, only: [:pay, :checkout]
def pay
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.merchant_id = 'merchant id'
Braintree::Configuration.public_key = 'public key'
Braintree::Configuration.private_key = 'private key'
gon.client_token = Braintree::ClientToken.generate()
end
def checkout
nonce = params[:payment_method_nonce]
result = Braintree::Transaction.sale :amount => @invoice.amount, :payment_method_nonce => "nonce-from-the-client"
if result.success?
message='Payment processed successfully. Thank you!'
@invoice.paid=true
@invoice.save
else
message='Unable to process payment. Reason = ' + result.message
end
redirect_to invoices_path, notice: message
end
private
def set_invoice
@invoice = Invoice.find(params[:id])
end
end
class PaymentsController@invoice.amount,:付款方法\u nonce=>“来自客户的nonce”
如果结果是成功?
消息:付款已成功处理。谢谢你
@发票。已付款=真实
@发票.保存
其他的
消息='无法处理付款。原因='+result.message
结束
重定向到发票路径,注意:消息
结束
私有的
def set_发票
@发票=发票.查找(参数[:id])
结束
结束
pay.html.erb:
<h1>Payments</h1>
<div>
<p>Invoice #: <%= @invoice.id %></p>
<p>Date: <%= @invoice.date %> </p>
<p>Description: <%= @invoice.description %> </p>
<p>Amount: <%= @invoice.amount %> </p>
</div>
<div class="form-container radius-box glassy-bg small-10 small-centered medium-8 large-6 columns">
<h2 class="mbs">New Transaction</h2>
<%= form_tag payments_checkout_path do%>
<%= hidden_field_tag 'id', @invoice.id %>
<p>Please enter your payment details:</p>
<div id="dropin"></div>
<%=submit_tag "Pay #{@invoice.amount}$", class: "button mt1" %>
<%end%>
</div>
付款
发票#:
日期:
说明:
金额:
新交易
请输入您的付款详细信息:
和布局/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Actionable Software</title>
<%= include_gon %>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
</head>
<body>
<%= render 'layouts/header' %>
<div class='container'>
<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, class: "alert alert-info") %>
<% end %>
<%= yield %>
</div>
</body>
</html>
可操作软件
正确%>
正确%>
我猜填充该元素的脚本的编写方式与TurboLink不同
试试看。或者干脆完全禁用它,看看它是否修复了它。我在我的应用程序中遇到了同样的问题。。在索引页上进行更改
<%= link_to 'Pay', payment_path(invoice.id) %>
到
这将迫使您在点击时完全加载支付页面
<%= link_to 'Pay', payment_path(invoice.id), data: { no_turbolink: true } %>