gpt4 book ai didi

javascript - 列表中的 Rails 4 ExecJS::ProgramError#index

转载 作者:太空宇宙 更新时间:2023-11-03 16:01:14 25 4
gpt4 key购买 nike

将 JavaScript 添加到我的网络应用程序后,我现在收到以下错误:

ExecJS::ProgramError in Listings#index

[stdin]:16:5: error: unexpected else
else
^^^^
(in /Users/Desktop/Rails/foodapp/app/assets/javascripts/orders.js.coffee)

application.html.etb

<!DOCTYPE html>
<html>
<head>
<title>Foodapp</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 %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= 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 == :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 %>

订单.js.咖啡

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
$('#new_order').append($('<input type="hidden" name="stripeToken" />').val(response.id))
$('#new_order')[0].submit()
else
$('#stripe_error').text(response.error.message).show()
$('input[type=submit]').attr('disabled', false)

listing.index.html.erb

<h2>All products</h2>

<table class="table table-striped">
<thead>
<tr>
<th class="center">Name</th>
<th class="center">Description</th>
<th class="center">Stock</th>
<th class="center">Price</th>
<th class="center">Sold by</th>
</tr>
</thead>

<tbody>
<% @listings.each do |listing| %>
<tr>
<td><%= listing.name %></td>
<td><%= listing.description %></td>
<td><%= listing.stock %></td>
<td><%= number_to_currency(listing.price) %></td>
<td><%= listing.user.name %></td>
<%= link_to 'Buy Now', listing, class: "btn btn-link" %>

</tr>

<% end %>
</tbody>
</table>

<br>

<% if user_signed_in? %>
<%= link_to 'New Listing', new_listing_path, class: "btn btn-link" %>
<% end %>

listings.show

<p>
<strong>Name:</strong>
<%= @listing.name %>
</p>

<p>
<strong>Description:</strong>
<%= @listing.description %>
</p>

<p>
<strong>Stock:</strong>
<%= @listing.stock %>
</p>

<p>
<strong>Price:</strong>
<%= number_to_currency(@listing.price) %>
</p>

<%= link_to "Buy It Now", new_listing_order_path(@listing), class: "btn btn-primary", data: { no_turbolink: true } %>

<% if current_user == @listing.user %>
<%= link_to 'Edit', edit_listing_path(@listing), class: "btn btn-link" %> |
<% end %>
<%= link_to 'Back', listings_path, class: "btn btn-link" %>

gem 文件

来源' https://rubygems.org '
来源' https://code.stripe.com '

ruby "2.0.0"
gem 'rails', '4.0.4'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'bootstrap-sass'
gem 'devise'
gem "figaro"
gem 'stripe'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

最佳答案

我遇到了同样的问题。
我猜这个错误是由数字 16 行的文本缩进引起的。

我正在使用 Sublime 3 编辑器。我的解决方案非常简单:
1. 更改编辑器窗口右侧和底部的 tab with = 2 属性。
2. 在同一侧选择Convert Indentation to Spaces

关于javascript - 列表中的 Rails 4 ExecJS::ProgramError#index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24417738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com