将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">×</button>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
</div>
<% end %>
<% end %>
orders.js.cofee
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" %>
的Gemfile
来源&#39; https://rubygems.org&#39;
来源&#39; https://code.stripe.com&#39;
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
答案 0 :(得分:2)
我遇到了同样的问题 我猜这个错误是由第16行的文本缩进引起的。
我正在使用Sublime 3编辑器。
我的解决方案非常简单:
1.在编辑器窗口的右下角更改tab with = 2
属性
2.在同一侧选择Convert Indentation to Spaces
。