ember.js - Serialize is reached before server response is complete -


in ember app, have router nested resources, so:

app.router.map(function () {   this.resource('explore', function() {     this.resource('building', { path: 'building/:slug' });     this.resource('country', { path: ':slug' }, function() {         this.resource('state', {path: ':slug' });     });   }); });  app.countryroute = ember.route.extend(app.slugrouter, {   setupcontroller: function(controller, country) {     controller.set('title', 'country detail');     controller.set('model', country);   } });  app.slugrouter = ember.mixin.create({     serialize: function(model, params) {         var name, object;         object = {};         name = params[0];         object[name] = model.get('slug');         return object;     } });  app.building = ds.model.extend({     country: ds.belongsto('app.country'),     name: ds.attr('string'),     slug: ds.attr('string') });  app.country = ds.model.extend({   name: ds.attr('string'),   slug: ds.attr('string'),   buildings: ds.hasmany('app.building'),   states: ds.hasmany('app.state') }); 

loading explore route shows list of buildings received server (a django-rest-framework app), each building has relationship country belongsto attribute.

in explore.index route, display list of buildings, links country route each building, using {{linkto this.country}}. href, however, loaded #/explore/undefined, instead of #/explore/<country-name>.

the part confusing me happens first time load list. if go route, come #/explore, links render correctly.

in debugger, putting breakpoint in serialize method, see first time load page, model object empty (_data.attributes empty object). going network tab in debugger, see request has been made server country data, response has not been received yet:

server response not received yet

the response received, since {{this.country.name}} renders correctly, after it's late.

thanks in advance responses/tips.

i using: ember: 1.0.0-rc.5, handlebars: 1.0.0-rc.4, jquery: 1.8.3, ember-data: 0.13, ember-data-django-rest-adapter: 0.13

firstly mixing in app.slugrouter before it's definition. should seeing error assertion failed: expected hash or mixin instance, got [object undefined] in console.

after need load model country slug. don't see in route either. need in countryroute depending on persistence library.

model: function(params) {   return app.country.find({slug: params.slug}); } 

i suspect part working right because index route loading model , passing in setupcontroller linkto. direct loading of nested page requires configuring route's model hook.


Comments