سؤال

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'
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top