2017-04-02 83 views
5

我試圖在我的rails應用程序中實現條紋元素,但我似乎無法正確包含stripe.js。這裏是我的application.htmlUncaught ReferenceError:條紋未定義 - 條紋錯誤

<%= tag :meta, name: "stripe-key", content: Figaro.env.stripe_publishable_key %> 
<script type="text/javascript" src="https://js.stripe.com/v3/"</script> 
<script type="text/javascript" src="https://js.stripe.com/v2/"></script> 

JS

var stripe = Stripe($("meta[name='stripe-key']").attr("content")) 
var elements = stripe.elements(); 

var card = elements.create('card', { 
    style: { 
    base: { 
     iconColor: '#999', 
     color: '#505652', 
     lineHeight: '40px', 
     fontWeight: 300, 
     fontFamily: 'Helvetica Neue', 

     '::placeholder': { 
     color: '#CFD7E0', 
     }, 
    }, 
    } 
}); 
// Add an instance of the card UI component into the `card-element` <div> 
card.mount('#card-element'); 

FORM

<form action="/charge" method="post" id="payment-form"> 
    <div class="form-row"> 
    <label for="card-element"> 
     Credit or debit card 
    </label> 
    <div id="card-element"> 
    </div> 
    <div id="card-errors"></div> 
    </div> 

    <button>Submit Payment</button> 
</form> 

每次我在控制檯Uncaught ReferenceError: Stripe is not defined - STRIPE ERROR加載頁面我得到這個錯誤。我認爲它與我加載stripe.js的方式有關,但我不確定?

+1

第一個'腳本'標記格式不正確。 – Artin

回答

5

我懷疑發生了什麼事是Stripe.js在你自己的javascript後加載。嘗試將Stripe.js移動到標題中您自己的JavaScript上方。