[英]Rails: Ember.js Handlebar templates not being recognized
I have a fairly basic question. 我有一个基本的问题。
I am learning Ember.js to be used with a Rails backend. 我正在学习Ember.js与Rails后端一起使用。 I can get things to work when templates are mentioned inline in the HTML file.
当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>
But the minute I moves this snippet to a .hbs file under templates directory, and include the following line in my application.js file, 但是,当我将此代码段移动到模板目录下的.hbs文件并在我的application.js文件中包括以下行的那一刻,
#= require_tree ./templates
they fail with this error. 他们因此错误而失败。
Assertion failed: You specified the templateName cms2/index for <CMS.IndexView:ember229>, but it did not exist.
I have tried to precompile then using two different Rubygems, 我尝试使用两种不同的Rubygems进行预编译,
gem 'handlebars_assets'
and 和
gem 'ember-rails'
From what I read, those two gems are supposed to precompile all .hbs files and including the templates directory tree should fix this problem. 据我了解,这两个gem应该可以预编译所有.hbs文件,包括模板目录树应该可以解决此问题。
What am I missing? 我想念什么? Why isn't this working for me?
为什么这对我不起作用?
Thanks. 谢谢。
Did you turn on the Ember support in Handlebars Assets? 您是否在“车把资产”中启用了Ember支持?
HandlebarsAssets::Config.ember = true
This will add the templates to the Ember.TEMPLATES namespace so they can be resolved. 这会将模板添加到Ember.TEMPLATES命名空间,以便可以对其进行解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.