Ok, I'm baffled. I am trying to set up a rails/backbons SPA. I am following along with this railscast: http://railscasts.com/episodes/323-backbone-on-rails-part-1?autoplay=true
I get this error from the browser when trying to access the root page:
ExecJS::RuntimeError in Main#index
Showing /Users/Eamon/raffle/raffler/app/views/layouts/application.html.erb where line #6 raised:
SyntaxError: unexpected }
(in /Users/Eamon/raffle/raffler/app/assets/javascripts/backbone/models/entry.js.coffee)
Extracted source (around line #6):
3: <head>
4: <title>Raffler</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
Here is my code - I only got a few minutes into the video.
raffler.js.coffee
#= require_self
#= require_tree ./templates
#= require_tree ./models
#= require_tree ./views
#= require_tree ./routers
window.Raffler =
Models: {}
Collections: {}
Routers: {}
Views: {}
init: ->
new Raffle.Routers.Entries()
Backbone.history.start()
$(document).ready ->
Raffler.init()
entries_router.js.coffee
class Raffler.Routers.EntriesRouter extends Backbone.Router
initialize: (options) ->
@entries = new Raffler.Collections.EntriesCollection()
@entries.reset options.entries
routes:
"new" : "newEntry"
'' : 'index'
":id/edit" : "edit"
":id" : "show"
newEntry: ->
@view = new Raffler.Views.Entries.NewView(collection: @entries)
$("#entries").html(@view.render().el)
index: ->
alert "home page"
show: (id) ->
entry = @entries.get(id)
@view = new Raffler.Views.Entries.ShowView(model: entry)
$("#entries").html(@view.render().el)
edit: (id) ->
entry = @entries.get(id)
@view = new Raffler.Views.Entries.EditView(model: entry)
$("#entries").html(@view.render().el)
I know most of the above code is irrelevant at this point in the cast...it was all created by the scaffold generator - I figured I didn't have to delete anything.
entry.js.coffee
class Raffler.Models.Entry extends Backbone.Model
paramRoot: 'entry'
defaults:
class Raffler.Collections.EntriesCollection extends Backbone.Collection
model: Raffler.Models.Entry
url: '/entries'
The above file is where I think the error is occurring. I just can't seem to find a syntax error anywhere. I noticed in the code that goes with the railscast on the cast page, that entry.js.coffee just has
class Raffler.Models.Entry extends Backbone.Model
I tried deleting everything but that line for the entry.js.coffee file - when I go to the root page...it just says "Loading...," which is just a reflection of the code used as a placeholder for before the app initializes.
Maybe a fresh pair of eyes...
UPDATE
I found someone with a similar issue here:
After seeing this and a few other related posts...I tried deleting the //=require_tree . line from application.js. A few other posts say it needs to be at the bottom...but mine already was, so that isn't the problem either. Incase it is relevant, here is my application.js file:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require backbone_rails_sync
//= require backbone_datalink
//= require backbone/raffler
//= require_tree .