Why doesn't the official emberjs guide for nested dynamic route work if you just follow it


#1

This has been Solved

I have followed all the rules for accessing a parent model from a child route out there that I have read from emberjs guide, to blogs , numerous stackoverflow answers and looking at various code samples on github.

After it all, clicking editcomment still returns null and the url for the nested dynamic segment is still undefined.

   posts/2/comments/undefined/edit

Infact in this example app, my route followed exactly what is in emberjs guides here: http://emberjs.com/guides/templates/links/#toc_multiple-contexts. See my jsfiddle and compare my route to theirs and you will see that is thesame: http://jsfiddle.net/VrR2T/2/

 App.Router.map(function() {
  this.resource("posts", function(){
  this.route('new');

     this.resource('post', {path: '/:post_id/'}, function(){
       this.route('comments');
       this.route('comment', {path: '/comments/:comment_id'});    
       this.route('editComment', {path: '/comments/:comment_id/edit'})           
   });
 });
});

All the guides I have read said we can access the parent model using modelFor. I did that and when I log to console, it is always the annoying null.

Ok, the guides also said we can directly do a find with the restAdapter and then filter out the result for what we want. I did that and that big null stayed me in the face despite the fact that when I drop to console and do thesame restAdapter find, I get back results.

Thirdly, if I say let me avoid the extra query with the restAdapter, since the data is already loaded anyway and just use the association to access child data in setupController using controllerFor since modelFor as used in the model hook hasn’t worked, I still ended with that same very frustrating null.

 App.PostEditCommentRoute = Ember.Route.extend({
   model: function(params) {
     var commentEdit = this.modelFor('post').get('comments');
     return commentEdit.get(params.comment_id);

    //return App.Comment.find({post: post.get('id'), id: params.comment_id});

    //var comment = this.modelFor('post').get('comments');
   //return comment.filterProperty('id', params.comment_id);  
  },

  setupcontroller: function( controller, model) {
    controller.set('content', model);
   }
}); 

That is the route with some of the permutations I have tried out. I have deleted others not to make the sample code to long.

Since this doesn’t work, clicking the edit form doesn’t bind to any of the existing comments in the fixtureAdapter.


#2

@yyy Did you figure this out?


#3

Yes Peter. That is why I put solved at the top. For any one that runs into this why searching. This is the working fiddle: http://jsfiddle.net/VrR2T/5/.


#4

That’s what I thought, just didn’t want to mark this as resolved without being certain.


#5