RailsCast的示例不起作用,Backbone on Rails,

时间:2014-05-03 14:00:34

标签: javascript ruby-on-rails ruby ruby-on-rails-3 backbone.js

我观看了这段视频:http://railscasts.com/episodes/323-backbone-on-rails-part-1 当我进入路由器的一部分索引页面时,我对视频进行了修改:

class CozinhaSolteiros.Routers.Recipes extends Backbone.Router
  routes:
    '' : 'index'
    index: ->
      alert "This is home page"

这不行,在我的主干文件中存在这个:

window.CozinhaSolteiros =
  Models: {}
  Collections: {}
  Views: {}
  Routers: {}
  initialize: ->
    new CozinhaSolteiros.Routers.Recipes()
    Backbone.history.start()

$(document).ready ->
  CozinhaSolteiros.initialize()

我使用Rails 4和像视频这样的gem backbone-on-rails,问题是警报doenst正常工作,浏览器控制台上什么都没有出现,错误是什么?我重新安装服务器,但没有任何改变。

1 个答案:

答案 0 :(得分:0)

在coffeescript中标记和间隔物质。你有:

class CozinhaSolteiros.Routers.Recipes extends Backbone.Router
  routes:
    '' : 'index'
    index: ->
      alert "This is home page"

你需要:

class CozinhaSolteiros.Routers.Recipes extends Backbone.Router
  routes:
    '' : 'index'
  index: ->
    alert "This is home page"