Ember.js 与 Rails 3.1 出现错误“无法找到模板”

发布于 2024-12-29 11:18:43 字数 1575 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

漫漫岁月 2025-01-05 11:18:43

您可能应该使用 ember-railsrasputin,但是同时使用这两种 gem 可能会导致不可预测的行为。由于它们都尝试注册和预编译您的车把模板,因此它们的目的是多余的,但它们的用法不同。

如果您查看 rasputin 的自述文件,您会发现模板在其路径中没有 templates 的情况下注册。因此,如果您想使用此 gem,则需要在 中将模板声明为 app/orders/list 而不是 app/templates/orders/list >App.ListOrdersView

You should probably use either ember-rails or rasputin, 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 without templates in their path. Therefore, if you want to use this gem, you'll need to declare your template as app/orders/list instead of app/templates/orders/list in App.ListOrdersView.

我的奇迹 2025-01-05 11:18:43

检查路径,也许它们应该是

//= require_tree ./app/models
//= require_tree ./app/controllers
//= require_tree ./app/views
//= require_tree ./app/helpers
//= require_tree ./app/templates

Unable to find template app/templates/order*s*/list

这是车把模板 app/templates/order/list.handlebars:

请参阅 < 中的路径差异强>s

check the paths, maybe they should be

//= require_tree ./app/models
//= require_tree ./app/controllers
//= require_tree ./app/views
//= require_tree ./app/helpers
//= require_tree ./app/templates

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

轻许诺言 2025-01-05 11:18:43

在更改模板定义和 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文