2012-10-05 17 views
0

我在Rails 3.2應用程序中使用haml_coffee_assets。以下作品在ejs模板中:Haml Coffee Assets Template錯誤,無法訪問Backbone JS模型?

<table> 
    <tr> 
    <th></th> 
    </tr> 
    <% tutorials.each(function(model) { %> 
    <tr> 
     <td><%= model.escape('title') %> 
    </tr> 
    <% }); %> 
</table> 

我似乎無法在haml_coffee中使用此工作。以下是我最好的猜測,但由於某種原因,這個haml_coffee模板不起作用:

%table 
    %thead 
    %tr 
     %th Tutorial Name 
    %tbody 
    - for tutorial in @tutorials 
     - do (model) -> 
     %tr 
     %td= model.title 

所有我這個得到的是:

ReferenceError: Can't find variable: model 

回答

3

既然你提到你正在使用一個GitHub的問題骨幹,我認爲@tutorials是骨幹收集和你也可以使用這種替代:

%table 
    %thead 
    %tr 
     %th Tutorial Name 
    %tbody 
    - for model in @tutorials.models 
     %tr 
     %td= model.escape('title') 
+0

是的,謝謝。我將更新問題以包含Backbone JS。這很棒。 – Dylan

1

我終於能夠出現以下這個工作:

%table 
    %thead 
    %tr 
     %th Tutorial Name 
    %tbody 
    - @tutorials.each (model) -> 
     %tr 
     %td= model.escape('title') 

希望這可以幫助其他人!