I have a save event set up with my post creation route.
App.PostsNewRoute = Ember.Route.extend({
model: function(){
return App.Post.createRecord();
},
exit: function() {
this._super();
this.get('currentModel.transaction').rollback();
},
setupController: function(controller, model){
controller.set('content', model);
},
events: {
save: function(post){
post.one('didCreate', this, function(){
this.transitionTo('posts.show', post);
});
post.get('transaction').commit();
},
cancel: function(){
this.transitionTo('posts.index');
}
}
});
Here is my post model.
App.Post = DS.Model.extend({
body: DS.attr('string'),
headline: DS.attr('string')
});
As you can see, it transitions to the show route after the post is created. I'm running into an issue where since the id of the post is undefined (it's defined after creation of the object in the database) the transition changes the url to /null . This seems logical, but obviously not ideal.
What is the best way to transition to the id of the new post? I return the whole object after it's created (with the ID included). Seems like Ember doesn't see the new object I'm returning.