在Rails中,我正在努力将Stripe集成到我正在开发的项目中。由于它是会员网站,我需要在用户创建帐户时收集cc数据。我已经安装了条纹gem并添加了键。
我在设计/注册/ new.html.erb
上有以下字段<div class="form-group">
<div class="row">
<div class="col-md-8">
<%= label_tag :card_number, "Credit Card Number" %>
<%= text_field_tag :card_number, nil, {:name => nil, :'data-stripe' => "number", class: "form-control"} %>
</div>
<div class="col-md-4">
<%= label_tag :card_code, "CVC" %>
<%= text_field_tag :card_code, nil, {:name => nil, :'data-stripe' => "cvc", class: "form-control"} %>
</div>
</div>
</div>
<div class="form-group">
<%= label_tag nil, "Expiration Date" %>
<div class="row">
<div class="col-md-3">
<%= select_month nil, { use_two_digit_numbers: true }, {:name => nil, :'data-stripe' => "exp-month", class: "form-control"} %>
</div>
<div class="col-md-3">
<%= select_year nil, { start_year: Date.today.year, end_year: Date.today.year+10 }, {:name => nil, :'data-stripe' => "exp-year", class: "form-control"} %>
</div>
</div>
</div>
接下来,我需要在提交表单时验证这些字段。我被指示用javascript执行此操作,因此我创建了一个新文件 registrations.js.coffee :
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
payment.setupForm()
payment =
setupForm: ->
$('#new_registration').submit ->
$('input[type=submit]').attr('disabled', true)
Stripe.card.createToken($('#new_registration'), payment.handleStripeResponse)
false
handleStripeResponse: (status, response) ->
if status == 200
alert(response.id)
else
alert(response.error.message)
当我在localhost上提交此表单时,收到错误消息: SyntaxError:[stdin]:14:5:意外如果 (在c:/Users/Bill/Desktop/testapp/app/assets/javascripts/registrations.js.coffee)
这行代码突出显示:
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
咖啡的实际缩进: