我不确定发生了什么,但看起来我的RoR应用程序中没有加载stripe.js
。我试图在每个视图的基础上加载它(因为我不想在其他页面上使用JS膨胀)。我已将其移至主布局页面(application.js),但这并没有什么区别。
视图/包/ new.html.erb
<div class="container">
<h1>
<a class="login-logo" href="#">
<%= image_tag "neo-logo.svg", alt: "Kernel-Ops - Network Ops Logo" %>
</a>
</h1>
<br/>
<div class="row login-container column-seperation">
<div class="col-md-6 col-md-offset-3">
<h2 class="text-center">You're almost done! We just need to collect your payment information.</h2>
<br/>
<br/>
<div class="row">
<div align="center" class="col-md-12">
<%= render 'form' %>
</div>
</div>
</div>
</div>
</div>
视图/包/ _form.html.erb
<%= form_tag packages_path, id: "payment_form" do %>
<%= hidden_field_tag 'package_id', @package.id %>
<%= hidden_field_tag 'email', current_user.email %>
<%= javascript_include_tag "https://js.stripe.com/v2/" %>
<script type="text/javascript"> Stripe.setPublishableKey("<%= Rails.configuration.stripe[:publishable_key] %>")</script>
<div class="form-group text-left">
<%= label_tag "Card Number", nil, required: true, class: "control-label" %>
<%= text_field_tag :card_number, nil, class: "form-control", "data-stripe" => "number" %>
</div>
<div class="form-group text-left">
<%= label_tag "Card Verification (CVV)", nil, required: true, class: "control-label" %>
<%= text_field_tag :card_verification, nil, class: "form-control", "data-stripe" => "cvv" %>
</div>
<div class="form-group text-left">
<%= label_tag "Card Expiration", nil, required: true, class: "control-label" %>
<div class="row">
<div class="col-md-6">
<%= select_tag :exp_month, options_for_select(Date::MONTHNAMES.compact.each_with_index.map { |name,i| ["#{i+1} - #{name}", i+1] }), include_blank: false, "data-stripe" => "exp-month", class: "form-control" %>
</div>
<div class="col-md-6">
<%= select_tag :exp_year, options_for_select((Date.today.year..(Date.today.year+10)).to_a), include_blank: false, "data-stripe" => "exp-year", class: "form-control" %>
</div>
</div>
</div>
<br/><br/>
<%= submit_tag "Submit Payment", class: "btn btn-success pull-right" %>
<%= link_to "Cancel", :back, { :class => "btn btn-danger pull-right", :style => "margin-right: 15px;" } %>
<% end %>
我在网络标签下查看Chrome调试器,但没有Stripe
的引用。由于已经加载了相当多的JS脚本,我还使用了脚本搜索功能来确认它不存在。
它在哪里?!
最后,如果我尝试提交表单,我会收到错误:
This customer has no attached payment source
这是有道理的,因为Stripe.js
无法做到这一点。
快速更新
将内联调用移到我的布局底部而不是表单中,现在我得到了:
控制台窗口中的 Uncaught ReferenceError: Stripe is not defined
。有趣的是,这是我的开发人员窗口向我显示的,表明Stripe.js已加载,但它仍然表现得像它没有: