投稿作成ルートで保存イベントを設定しました。
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');
}
}
});
これが私の投稿モデルです。
App.Post = DS.Model.extend({
body: DS.attr('string'),
headline: DS.attr('string')
});
ご覧のとおり、投稿が作成された後、表示ルートに移行します。投稿のIDが未定義(データベースでのオブジェクトの作成後に定義されている)であるため、遷移によってURLが/nullに変更されるという問題が発生しています。これは論理的に思えますが、明らかに理想的ではありません。
新しい投稿のIDに移行するための最良の方法は何ですか?オブジェクトが作成された後(IDを含めて)オブジェクト全体を返します。Emberは私が返している新しいオブジェクトを認識していないようです。