首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExecJS::Listings#index错误中的运行时错误

ExecJS::Listings#index错误中的运行时错误
EN

Stack Overflow用户
提问于 2014-09-03 02:42:08
回答 1查看 4.2K关注 0票数 3

当我打开本地主机ExecJS时,我收到了这条错误消息,我不知道为什么,一些帮助将是惊人的。

我把这个放在我的本地主机上

显示第6行所显示的/.../conektec/app/views/layouts/application.html.erb:

SyntaxError: stdin:6:16:意外换行符(在SyntaxError中)

代码语言:javascript
复制
  ActionView::Template::Error (SyntaxError: [stdin]:2:73: unmatched )
  (in /Users/hbendev/startups/conektec/conektec/app/assets/javascripts/orders.js.coffee)):
    3: <head>
    4:   <title>Conektec</title>
    5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    6:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    7:   <%= javascript_include_tag "https://js.stripe.com/v2/" %> 
    8:   <%= csrf_meta_tags %>
    9:   <%= tag :meta, :name => "stripe-key", :content => ENV["STRIPE_PUBLIC_KEY"] %>

这是我的orders.js.coffee文件

代码语言:javascript
复制
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文件

代码语言:javascript
复制
<!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">&times;</button>
                <%= content_tag :div, msg, :id => "flash_#{name}" %>
            </div>
        <% end %>
    <% end %>

    <%= yield %>

    <%= render 'layouts/footer' %>
</div>


</body>
</html>

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

我使用的是: OS小牛Ruby 2.0.0 Rails 4.1.1

,怎么了?,谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-03 03:55:09

您的问题出现在您的CoffeeScript语法中(第6行,第16列,正如它在错误中所述):

代码语言:javascript
复制
# 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错误。

要解决另一个问题,因为我不能评论,您需要缩进您的handleStripeResponse函数,以便将它嵌套在您的支付对象下面:

代码语言:javascript
复制
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时非常小心。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25635395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档