清单中的ExecJS :: RuntimeError索引错误

当我打开本地主机时 ,我收到此ExecJS错误消息 ,我不知道为什么,一些帮助会很惊人。

我在我的localhost上得到了这个

显示/…/conektec/app/views/layouts/application.html.erb,其中第6行引发:

SyntaxError:[stdin]:6:16:意外的换行符(在/…/conektec/app/assets/javascripts/orders.js.coffee中)

ActionView::Template::Error (SyntaxError: [stdin]:2:73: unmatched ) (in /Users/hbendev/startups/conektec/conektec/app/assets/javascripts/orders.js.coffee)): 3:  4: Conektec 5:  true %> 6:  true %> 7:  8:  9:  "stripe-key", :content => ENV["STRIPE_PUBLIC_KEY"] %> 

这是我的orders.js.coffee文件

 jQuery -> Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content')) payment.setupForm() payment = setupForm: -> $('#new_order').submit -> $('input[type=submit]').attr('disabled', true) Stripe.card.createToken($('#new_order'), payment.handleStripeResponse) false handleStripeResponse: (status, response) -> if status == 200 alert(response.id) else alert(response.error.message) 

这是我的application.html.erb文件

    Conektec  true %>  true %>    "stripe-key", :content => ENV["STRIPE_PUBLIC_KEY"] %>    
<div class="alert alert- alert-dismissable"> "flash_#{name}" %>

我已经尝试删除我的turbolinks ,添加rubyracer gem,我安装了nodejs ,我不知道错误在哪里。

我正在使用: OS X Mavericks Ruby 2.0.0 Rails 4.1.1

怎么了? 谢谢

您的问题在于您的CoffeeScript语法(第6行,第16行,因为它在错误中说明):

 # The lack of indentation after the setupForm line is incorrect payment = setupForm: -> $('#new_order').submit -> $('input[type=submit]').attr('disabled', true) Stripe.card.createToken($('#new_order'), payment.handleStripeResponse) false # Make it this payment = setupForm: -> $('#new_order').submit -> $('input[type=submit]').attr('disabled', true) Stripe.card.createToken($('#new_order'), payment.handleStripeResponse) false 

编辑:值得注意的是,每当出现ExecJS错误时,通常都是一个很好的迹象,表明您的CoffeeScript语法存在问题(从而导致编译错误)。 在这种情况下,这不是一个真正的JavaScript错误。

要解决您遇到的OTHER问题,因为我无法发表评论,您需要缩进handleStripeResponse函数,以便它嵌套在您的付款对象下面:

 jQuery -> Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content')) payment.setupForm() payment = setupForm: -> $('#new_order').submit -> $('input[type=submit]').attr('disabled', true) Stripe.card.createToken($('#new_order'), payment.handleStripeResponse) false handleStripeResponse: (status, response) -> if status == 200 alert(response.id) else alert(response.error.message) 

我不确定你是如何得到这些错误的,认为它们是直接从Railscasts插曲中复制出来的; 试着用CoffeeScript小心缩进你的缩进。