Ember.js 与 Rails 3.1 出现错误“无法找到模板”
我正在尝试使用 Rails 3.1 设置 Ember.js ,但我在 Firebug 控制台中收到以下错误:
uncaught exception: Error: <(subclass of App.ListOrdersView):ember201> - Unable to find template "app/templates/orders/list".
我按照本指南。这是我的清单文件,它正确加载了所有 js:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require vendor/ember
//= require vendor/ember-rest
//= require_tree ./../lib
//= require app/app
//= require_tree ./../app/models
//= require_tree ./../app/controllers
//= require_tree ./../app/views
//= require_tree ./../app/helpers
//= require_tree ./../app/templates
//= require_self
这是车把模板 app/templates/order/list.handlebars:
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{#each orders}}
{{view App.ShowOrderView orderBinding="this"}}
{{/each}}
</tbody>
</table>
以及 Rails 视图文件 app/views/orders/index.html.haml
%script{:type => "text/x-handlebars"}
= hb 'view App.ListOrdersView'
:javascript
$(function() {
App.ordersController.loadAll(#{@orders.to_json.html_safe});
});
最后是 Ember 的 gems。 js,在 Gemfile 中:
# Ember
gem 'ember-rails'
gem 'hamlbars', :git => "https://github.com/jamesotron/hamlbars.git"
gem 'rasputin'
I'm trying to setup Ember.js with Rails 3.1 and I'm getting the following error in the Firebug console:
uncaught exception: Error: <(subclass of App.ListOrdersView):ember201> - Unable to find template "app/templates/orders/list".
I followed this guide. Here is my manifest file, which correctly loads all the js:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require vendor/ember
//= require vendor/ember-rest
//= require_tree ./../lib
//= require app/app
//= require_tree ./../app/models
//= require_tree ./../app/controllers
//= require_tree ./../app/views
//= require_tree ./../app/helpers
//= require_tree ./../app/templates
//= require_self
This is the handlebar template app/templates/order/list.handlebars:
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{#each orders}}
{{view App.ShowOrderView orderBinding="this"}}
{{/each}}
</tbody>
</table>
And the Rails view file app/views/orders/index.html.haml
%script{:type => "text/x-handlebars"}
= hb 'view App.ListOrdersView'
:javascript
$(function() {
App.ordersController.loadAll(#{@orders.to_json.html_safe});
});
Finally the gems for Ember.js, in Gemfile:
# Ember
gem 'ember-rails'
gem 'hamlbars', :git => "https://github.com/jamesotron/hamlbars.git"
gem 'rasputin'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能应该使用
ember-rails
或rasputin
,但是同时使用这两种 gem 可能会导致不可预测的行为。由于它们都尝试注册和预编译您的车把模板,因此它们的目的是多余的,但它们的用法不同。如果您查看
rasputin
的自述文件,您会发现模板在其路径中没有templates
的情况下注册。因此,如果您想使用此 gem,则需要在中将模板声明为
。app/orders/list
而不是app/templates/orders/list
>App.ListOrdersViewYou should probably use either
ember-rails
orrasputin
, but using both gems together might lead to unpredictable behavior. Since they both attempt to register and precompile your handlebars templates, they are redundant in purpose but their usage differs.If you look at the readme for
rasputin
, you'll see that templates get registered withouttemplates
in their path. Therefore, if you want to use this gem, you'll need to declare your template asapp/orders/list
instead ofapp/templates/orders/list
inApp.ListOrdersView
.检查路径,也许它们应该是
Unable to find template app/templates/order*s*/list
这是车把模板 app/templates/order/list.handlebars:
请参阅 < 中的路径差异强>s
check the paths, maybe they should be
Unable to find template app/templates/order*s*/list
This is the handlebar template app/templates/order/list.handlebars:
see the path difference in s
在更改模板定义和 ember gems 时,我遇到了类似的问题。尽管错误是相同的(抱怨模板路径 - 尽管所有路径看起来都是正确的),但只需要使用
rake assets:clean
来解决问题。I ran into similar issues when changing template definitions and ember gems. Although the error was the same (complaining about the template path - even though the paths all seemed correct), all it took was a
rake assets:clean
to get things sorted out.