我收到了以下路由器代码:
class App.Routers.MainRouter extends Backbone.Router
routes:
'': 'index'
index: ->
console.log "whatever"
从Rails获得以下错误
ActionView::Template::Error ([stdin]:1:84: error: unexpected :
console.log "whatever"er extends Backbone.Router
^
(in /Users/ivan/projects/ruby/backbone-example/app/assets/javascripts/backbone/routers/main_router.js.coffee)):
15: = favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72'
16: = favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png'
17: = favicon_link_tag 'favicon.ico', :rel => 'shortcut icon'
18: = javascript_include_tag "application"
19:
20:
21: %body
app/views/layouts/application.html.haml:18:in `_app_views_layouts_application_html_haml___4072892406181986467_2205219860'
execjs (2.2.1) lib/execjs/ruby_racer_runtime.rb:47:in `rescue in block in call'
execjs (2.2.1) lib/execjs/ruby_racer_runtime.rb:43:in `block in call'
execjs (2.2.1) lib/execjs/ruby_racer_runtime.rb:78:in `block in lock'
execjs (2.2.1) lib/execjs/ruby_racer_runtime.rb:76:in `call'
execjs (2.2.1) lib/execjs/ruby_racer_runtime.rb:76:in `Locker'
execjs (2.2.1) lib/execjs/ruby_racer_runtime.rb:76:in `lock'
execjs (2.2.1) lib/execjs/ruby_racer_runtime.rb:42:in `call'
coffee-script (2.2.0) lib/coffee_script.rb:57:in `compile'
无法解决我的问题?
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
的Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.1.4'
gem 'pg'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyracer', platforms: :ruby
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spring', group: :development
gem 'rails-backbone', github: 'codebrew/backbone-rails', branch: 'master'
gem 'twitter-bootstrap-rails'
gem 'haml-rails'
的application.js
//= require jquery
//= require twitter/bootstrap
//= require underscore
//= require backbone
//= require backbone/backbone_example
backbone_example.js.coffee
#= require_self
#= require_tree ./templates
#= require_tree ./models
#= require_tree ./views
#= require_tree ./routers
window.App =
Models: {}
Collections: {}
Routers: {}
Views: {}
initialize: ->
new App.Routers.MainRouter()
Backbone.history.start()
如果我删除这两行 路线: '':'索引' coffeescript编译成功,所以问题就在那里。 另一个奇怪的事情,如果我复制n将此文件粘贴到js2coffee.org,它也会成功编译它。
答案 0 :(得分:2)
您的代码中可能有一些杂散的回车符(CR - \ r)字符,或者您的编辑器没有向您显示的其他ASCII字符。
答案 1 :(得分:0)
我看到的第一件事是您错误拼写extends
关键字:
class App.Routers.MainRouter exetends Backbone.Router
应为extends
:
class App.Routers.MainRouter extends Backbone.Router