Ember.js 资产管道“无法找到模板”;
我无法在 Rails 3.1 中访问我的车把模板。我有以下控制器:
Lead.Controllers.UrlSearch = Ember.Object.extend
init: ->
view = Ember.View.create
controller: @
urlSearchBinding: 'controller.url_search'
templateName: 'app/templates/url_search/show'
在 Rails 方面,我在 config/initializers/sprockets.rb 中有以下初始化脚本
require 'sprockets/ember_handlebars'
Rails.application.assets.register_engine 'hjs', EmberHandlebars
我的 EmberHandleBars 如下所示:
require 'tilt'
require 'json'
class EmberHandlebars < Tilt::Template
def self.default_mime_type
"application/javascript"
end
def prepare
end
def evaluate(scope, locals, &block)
"Ember.TEMPLATES['#{scope.logical_path}'] = Ember.Handlebars.compile(#{data.to_json})"
end
end
最后,模板位于:
app/assets/javascripts/app/templates/url_search/show.jst.hjs
在错误控制台中,我收到此 404 资源错误:
GET
http://localhost:3000/assets/app/templates/url_search/show.hjs.js?body=1
404 (Not Found)
并且
错误:- 无法找到模板 “应用程序/模板/url_search/show”。
我很困惑为什么当我另有指定时它正在寻找 hjs.js 文件以及为什么它找不到模板。
谁能看到我做错了什么吗?
I am having trouble getting my handlebars templates accessible in rails 3.1. I have the following controller:
Lead.Controllers.UrlSearch = Ember.Object.extend
init: ->
view = Ember.View.create
controller: @
urlSearchBinding: 'controller.url_search'
templateName: 'app/templates/url_search/show'
On the rails side of things, I have a the following initialisation script in config/initializers/sprockets.rb
require 'sprockets/ember_handlebars'
Rails.application.assets.register_engine 'hjs', EmberHandlebars
My EmberHandleBars looks like this:
require 'tilt'
require 'json'
class EmberHandlebars < Tilt::Template
def self.default_mime_type
"application/javascript"
end
def prepare
end
def evaluate(scope, locals, &block)
"Ember.TEMPLATES['#{scope.logical_path}'] = Ember.Handlebars.compile(#{data.to_json})"
end
end
Finally, the template is located in:
app/assets/javascripts/app/templates/url_search/show.jst.hjs
In there error console, I get this 404 resource error:
GET
http://localhost:3000/assets/app/templates/url_search/show.hjs.js?body=1
404 (Not Found)
and also
Error: - Unable to find template
"app/templates/url_search/show".
I am confused why it is looking for an hjs.js file when I have specified otherwise and why it cannot find the template.
Can anyone see what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将文件扩展名从 .jst.hjs 更改为 .hjs 解决了该问题。
Changing the file extensions form .jst.hjs to just .hjs fixed the problem.