2012-04-08 33 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

我重新輸入了代碼,現在按原樣工作。這一定與咖啡腳本中的縮進有關。