0

I get an "unable to find template" error when I fire up my DOM. Here's my code:

//javascripts/app/app.js
MyApp = Ember.Application.create();

MyApp.store = DS.Store.create({
  revision: 4,
  adapter: DS.RESTAdapter.create({ bulkCommit: false })
});

//javascripts/app/models/event.js
MyApp.Event = DS.Model.extend({
    id: DS.attr('number'),
    league_id: DS.attr('number')
});

//javascripts/app/controllers/event.js
MyApp.eventsController = Ember.ArrayController.create({
      content: [],

      init: function() {
        this.content = jQuery.get('events.json');
      }
});

//javascripts/app/views/events/list.js
MyApp.EventListView = Ember.View.extend({
  templateName: 'app/templates/events/list',
  eventsBinding: 'MyApp.eventsController'
});

//javascripts/app/templates/events/list.handlebars
{{#each events}}
    {{view MyApp.EventListView eventsBinding='this'}}
{{/each}}

//app/views/events/index.html.erb
<script type='text/x-handlebars'>
  {{ view MyApp.EventListView }}
</script>

I tried one of the fixes suggested in this Q&A, but couldn't get it to work for me. What I am doing wrong?

Community
  • 1
  • 1
keruilin
  • 16,782
  • 34
  • 108
  • 175

1 Answers1

2

For you error, if the whole code is here, you missed the <script> tag in you handlebars list template:

<!-- conforms to MyApp.EventListView templateName property -->
<script type='text/x-handlebars' data-template-name="list">
   {{#each events}}
<!-- you dont have to insert {{view MyApp.EventListView eventsBinding='this'}} 
here, as I think you want to manipulate an event -->
       {{league_id}} 
   {/each}}
</script>

By the way, the init method of your controller is wrong:

MyApp.eventsController = Ember.ArrayController.create({
  content: [],

  init: function() {
    this._super(); // when you override init(),
                   // you have to call the super class init().

    this.set('content', jQuery.get('events.json')); 
    // that the way to set properties with ember. You have to use this.
  }
});

If it does not help, as @Rajat suggest you, please post a jsfiddle of the complete code.

sly7_7
  • 11,961
  • 3
  • 40
  • 54