Rails 4:Ember.js看不到我的模板?

时间:2013-11-03 10:21:34

标签: ruby-on-rails ember.js handlebars.js

我正在尝试从templates/about.handlebars呈现模板。

我在rails视图中设置了插座:

%script{ type: 'text/x-handlebars'}
  <h1> My app</h1>
  {{ outlet }}
  ^-- outlet

about路线看起来像这样:

Admin.Router.map ->
  @route 'about', path: '/'

关于模板是简单的html:

<h1>This is ABOUT!</h1>

似乎有效:

  • 我可以看到Ember调试消息,确认ember正在运行
  • 我安装了ember chrome扩展程序,它可以看到应用程序模板

但是,当我要求Ember.TEMPLATES时,我得到:

Object {application: function} 
application: function (context, options) { 
__proto__: Object

并且没有关于那里的模板。

在已编译的js文件中挖掘,我可以看到车把模板在物理上存在:

(function() {
  this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
  this.HandlebarsTemplates["about"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
  this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};



  return "\n<h1>This is ABOUT!</h1>\n\n";
  });
  return this.HandlebarsTemplates["about"];
}).call(this);

但我没有看到它被明确添加到Ember.TEMPLATES。

更新1:检查ember-rails gem,我看到了把手will match only files that have .raw.(hjs|...), or mustache.(hjs|...) in their names?文档似乎没有谈到这一点。

即使我重命名模板,它仍然没有显示,它的晚餐很奇怪,因为我没有在教程或gem文档中看到类似的模板名称。

1 个答案:

答案 0 :(得分:0)

Ember在Ember.TEMPLATES中查找预编译的模板,而不是HandlebarsTemplates。