Javascript ExecJS::清单中的RuntimeError#索引错误
当我打开我的本地主机时,我收到了这个ExecJS错误消息,我不知道为什么,一些帮助将是惊人的 我在本地主机上得到了这个 显示/../conektec/app/views/layouts/application.html.erb,其中第6行出现: 语法错误:[stdin]:6:16:意外换行 (在/../conektec/app/assets/javascripts/orders.js.coffee中) 这是我的application.html.erb文件Javascript ExecJS::清单中的RuntimeError#索引错误,javascript,ruby-on-rails,ruby,node.js,coffeescript,Javascript,Ruby On Rails,Ruby,Node.js,Coffeescript,当我打开我的本地主机时,我收到了这个ExecJS错误消息,我不知道为什么,一些帮助将是惊人的 我在本地主机上得到了这个 显示/../conektec/app/views/layouts/application.html.erb,其中第6行出现: 语法错误:[stdin]:6:16:意外换行 (在/../conektec/app/assets/javascripts/orders.js.coffee中) 这是我的application.html.erb文件 科内克泰克 正确%> 正确%> “条带
科内克泰克
正确%>
正确%>
“条带密钥”:content=>ENV[“条带公钥”]%>
&时代;
“flash{name}”%>
我已经尝试删除我的TurboLink,添加rubyracer gem,我已经安装了nodejs,我不知道哪里出了错误
我正在使用:
OSX小牛
Ruby 2.0.0
轨道4.1.1
怎么了?谢谢您的问题在于您的CoffeeScript语法(第6行第16列,如错误中所述): 编辑:值得注意的是,每当出现ExecJS错误时,这通常是一个很好的迹象,表明您的CoffeeScript语法存在问题(从而导致编译错误)。在这种情况下,这不是一个实际的JavaScript错误。” 要解决您遇到的另一个问题,由于我无法发表评论,您需要缩进
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事件中复制的;试着对咖啡脚本的缩进要非常小心 这是你咖啡脚本中真正的缩进吗?你认为Stripe.setPublishableKey($)('meta[name=“Stripe key”]”)可以吗?哦,我刚刚意识到缩进是真的。我修好了。现在错误已经过去了,但还有一个问题,当我点击提交按钮(请参阅coffeescript代码)时,我在浏览器(Chrome)中没有收到任何弹出消息,唯一的操作是.attr('disabled',true),它在我单击按钮后禁用该按钮。我将
Stripe.setPublishableKey($)('meta[name=“Stripe key”]').attr('content'))
的代码编辑为:Stripe.setPublishableKey($('meta[name=“Stripe key”]')).attr('content'))
,同样的错误,没有出现警报。感谢SO hall监视器再次关闭了一个有用的问题,这样他们就可以成为房间里最聪明的人。@user1130176不知道你的意思-我不是结束这个问题的人。我差不多三年前就回答了这个问题。我只是在发泄,我绝对不喜欢人们在向别人提供价值的时候,把这么近距离的问题当作离题。这只是幼稚的自负,对任何人都没有好处。
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)
<!DOCTYPE html>
<html>
<head>
<title>Conektec</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= javascript_include_tag "https://js.stripe.com/v2/" %>
<%= csrf_meta_tags %>
<%= tag :meta, :name => "stripe-key", :content => ENV["STRIPE_PUBLIC_KEY"] %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |name, msg| %>
<% if msg.is_a?(String) %>
<div class="alert alert-<%= name.to_s == 'notice' ? "success" : "danger" %> alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
</div>
<% end %>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
# 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
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)