1

I have a following route definition in my ember-rails project. The file is /app/assets/javascripts/routes/applicationRoute.js.coffee and the code is as follows:

ChAdmin.ApplicationRoute = Ember.Route.extend (
   model: ()->
     store = @.get("store")
     store.push("tapahtuma",
       id: 1,
       nimi: "test1",
       paiva: "11.1.2012"
     )

)

This prevents the application template from rendering. Can anyone tell me why is that? I can see from embers inspector that the item has been pushed to store. If I do anything else except push items in the store the app template renders just fine.

There are no errors in javascript console and starting the app I get:

DEBUG: ------------------------------- ember.js?body=1:394
DEBUG: Ember.VERSION : 1.0.0 ember.js?body=1:394
DEBUG: Handlebars.VERSION : 1.0.0 ember.js?body=1:394
DEBUG: jQuery.VERSION : 1.10.2 ember.js?body=1:394
DEBUG: ------------------------------- ember.js?body=1:394
Ember Debugger Active

Any help would be much appreciated.

CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43
Jukka Puranen
  • 8,026
  • 6
  • 27
  • 25

2 Answers2

1

You should return the model from model()

App.IndexRoute = Ember.Route.extend({
  model: function(){
    var store = this.get('store');
    store.push("tapahtuma",
      {
         id: 1,
         nimi: "test1",
         paiva: "11.1.2012"
      }
     );
    // model is expected to return the object or 
    // a promise that resolve into the object
    return store.find('tapahtuma',1); 
  }
});

More details on the model() hook in the emberjs guide on routing.

JSBin example

CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43
  • Adding return only makes model data render. As you can see from your JSBin example, if you remove the return statement application template still renders. You put me on the right track though. Since your example used a newer version of ember-data, I updated my ember & ember-data versions and now the app template renders correctly. – Jukka Puranen Oct 07 '13 at 20:00
0

Problem was an old version of ember-data. I ran "rails generate ember:install --head" and now the application template renders correctly.

Jukka Puranen
  • 8,026
  • 6
  • 27
  • 25