2012-04-08 32 views
0

我跟随着Ryan Bates RailsCast Backbone.js教程。这张图片是他教程的截图。rails:backbone-on-rails gem文件命名约定负责错误?

enter image description here

注意,在views /项/目录下,有一个名为 “entries_index.js.coffee” 文件

当我产生我的脚手架,该文件被简称为index.js.coffee

这可能很重要,因为瑞安在EntriesIndex实例化路由器中的视图。

index: -> 
    new Raffler.Views.EntriesIndex() 
    $('#container').html(view.render().el) 

,然后在entries_index.js.coffee文件渲染模板

render: -> 
    $(@el).html(@template()) 
    this 

其中,用于演示,只是应该把这个容器DIV

<h1>Raffler</h1> 

然而,当我这样做,我得到这个错误在Firebug

view is not defined 
[Break On This Error] 

return $('#container').html(view.render().el); 

由于文件名entries_index.js.coffee v index.js.coffee的区别,我想知道Ryan是否有意义以这种方式实例化视图(即,骆驼情况下采取下划线的地方)

new Raffler.Views.EntriesIndex() 

如果我改变它,尝试

new Raffler.Views.Index() 

我得到的错误

Raffler.Views.Index is not a constructor 
[Break On This Error] 

new Raffler.Views.Index(); 

任何想法如何,我可以重回正轨?

回答

0

我重新输入了代码,现在按原样工作。这一定与咖啡脚本中的缩进有关。