How to define route name for nested resource in Ember.js? -
i've got nested resources in ember routes. lets suppose according this example, router.js
looks like:
app.router.map(function() { this.resource('post', { path: '/post/:post_id' }, function() { this.resource('comment', { path ':comment_id' }); }); });
the documentation says should generate routes like:
/post/:post_id post.index /post/:post_id/:comment_id comment.index
however these post.show
, comment.show
, how rename these routes?
i have working following setup.
routers dynamic segment:
app.router.map(function() { this.resource('post.show', { path: '/post/:post_id' }); this.resource('comment.show', { path: '/post/:post_id/:comment_id' }); });
overriding serialize
hook of app.commentshowroute
reflect url expected:
app.commentshowroute = ember.route.extend({ serialize: function(model) { return { post_id : model.get("post_id"), comment_id : model.get("id") }; } });
the major problem implementating url generated, since model in serialize
hook, isn't loaded, post_id
property isn't present, , after model loaded isn't automatically updated. linkto
targeting comment have url post/undefined/1
, instead of post/1/1
. clicking in link works, because after time model loaded, if user refresh page, not work, because of wrong url.
to fix it, used 3 approach this discussion forum comment, use action
helper instead of linkto
. diference link not have href` property url, when clicking works.
the result that:
app.postshowroute = ember.route.extend({ events : { gotocomment: function(context){ this.transitionto('comment.show', context); } } });
here demo full implementation.
Comments
Post a Comment