将把手模板编译成Rails

时间:2013-02-05 11:01:27

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

当我正在努力让ember运行时,我现在无法通过资产管道加载我的车把模板。 我正在使用handlebars_assets gem,当我点击服务器时,我得到的是下面的内容,我确认路径是正确的,但不确定如何解决这个问题。 当我需要handlebars.runtime:

couldn't find file 'handlebars.runtime'
  (in /Users/tspore/Rails/Active/tombfinder/app/assets/javascripts/app/ember_app.js:1)

Cache read: sprockets/6f42a4ba0f2b80167ce50f9f306427fa
Compiled app/ember_app.js  (5ms)  (pid 9791)
Cache read: sprockets/764613d8100bb6d8e6072701f79183c1
Completed 500 Internal Server Error in 141ms

ActionView::Template::Error (can't convert nil into String
  (in /Users/tspore/Rails/Active/tombfinder/app/assets/javascripts/app/templates/records/index.hbs)):
    26:   <% end %>
    27: 
    28: 
    29:   <%= javascript_include_tag 'app/ember_app' %>
    30: </head>
    31: <body class="<%= @class %>">
    32: <div id="center">
  app/views/layouts/js.html.erb:29:in `_app_views_layouts_js_html_erb__854441834177334479_70351597254240'
  app/controllers/js/js_controller.rb:3:in `index'

Rendered /Users/tspore/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.1.10/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms)
Rendered /Users/tspore/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.1.10/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.6ms)
Rendered /Users/tspore/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.1.10/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (3.0ms)

编辑:使用Github版本,并从:资产中删除宝石 - 它似乎工作。但现在我收到了这个错误 -

未捕获的ReferenceError:HandlebarsTemplates未定义records_view.js:4 未捕获错误:断言失败:无法在路径“App.listRecordsView”找到视图

我的应用程序看起来像这样 -

App.listRecordsView = Ember.View.extend({
   templateName: HandlebarsTemplates['records/index'](context)
});

使用ember-rails gem我得到了gem来编译所以现在我有一个名为layout.js的脚本,如下所示:

Ember.TEMPLATES["app/templates/controller/layout"] = Ember.Handlebars.template(function anonymous(Handlebars, depth0, helpers, partials, data) { helpers = helpers || Ember.Handlebars.helpers; data = data || {};
  var buffer = '', stack1, hashTypes, escapeExpression=this.escapeExpression;    
  data.buffer.push("<h1>from template</h1>\n");
  stack1 = {};
  hashTypes = {};
  stack1 = helpers._triageMustache.call(depth0, "outlet", {hash:stack1,contexts:[depth0],types:["ID"],hashTypes:hashTypes,data:data});
  data.buffer.push(escapeExpression(stack1) + "\n");
  return buffer;
});

如何在Ember应用程序中调用此模板?它没有名称空间可以说: templateName:'layout'

0 个答案:

没有答案