2014-02-27 38 views
0

我有一個相當基本的問題。Rails:Ember.js手柄模板不被識別

我正在學習用於Rails後端的Ember.js。當HTML文件中內嵌模板時,我可以使事情發揮作用。

<script type="text/x-handlebars" id="index"> 
<div class="container-fluid"> 
    <div class="row-fluid"> 
     <div class="span3"> 
      <table class='table'> 
       <thead> 
       <tr><th>Recent Posts</th></tr> 
       </thead> 
       {{#each item in model}} 
        <tr><td> 
         {{item.name}} 
        </td></tr> 
       {{/each}} 
      </table> 
     </div> 
     <div class="span9"> 
      {{outlet}} 
     </div> 
    </div> 
</div> 
</script> 

不過分鐘我移動這個片段,以模板目錄下的.hbs文件,包括在我的application.js文件中的以下行,

#= require_tree ./templates 

他們失敗,此錯誤。

Assertion failed: You specified the templateName cms2/index for <CMS.IndexView:ember229>, but it did not exist. 

我試圖預編譯,然後使用兩個不同的RubyGems,

gem 'handlebars_assets' 

gem 'ember-rails' 

從我讀,這兩種寶石都應該預編譯所有.hbs文件和包括模板目錄樹應該可以解決這個問題。

我錯過了什麼?爲什麼這不適合我?

謝謝。

回答

1

您是否在Handlebars資產中啓用了Ember支持?

HandlebarsAssets::Config.ember = true 

這會將模板添加到Ember.TEMPLATES命名空間中,以便它們可以解析。

+0

buuda - 感謝您的提示。 我沒有添加,但添加到environment.rb沒有修復錯誤。 然後我發現我在application.js中特別添加了handlebars-1.0.0。我用#=需要把手替換它,並修復了錯誤。 但現在,模板沒有被加載,甚至沒有應用程序模板。 Ember.TEMPLATES說明如下: 對象{../cms2/templates/application:function,../cms2/templates/index:function} ../cms2/templates/application:function(context,選項){ ../cms2/templates/index:function(context,options){' –

+0

我得到這個工作,但它感覺像一個黑客。 我要創建兩個視圖,並設置這樣的模板: 'window.CMS.IndexView = Ember.View.extend 模板:Ember.TEMPLATES [ '../ CMS2 /指數']' 這似乎上班。如果我使用templateName,它不起作用。我必須失去一些明顯的東西。 感謝您的幫助。 –