2
votes

I'm building a social app with Ember using the Ember App Kit as a basis. The index page renders fine. On navigating to the nested model, the route fires correctly, and there are no errors in the console, but the view doesn't render. Here is the relevant code:

console

Rendering friend with <(subclass of Ember.View):ember2698> Object {fullName: "view:friend"}
Transitioned into 'friends.friend'

routes/friends.js

var FriendsRoute = Ember.Route.extend({
  model: function(params) {
    return $.getJSON('JSON_ROUTE').then(function(data){
      return data.friends.map(function(friend) {
        return friend;
      });
    });
  }
});

export default FriendsRoute;

router.js

Router.map(function() {
  this.resource('friends', function() {
    this.resource('friend', { path: '/:friend_id' });
  });
});

export default Router;

templates/friends.hbs

<div class="friends-list">
    {{#each model}}
        {{#link-to 'friend' this }}
            {{{display_name}}}
        {{/link-to}}
    {{/each}}
</div>
<div class="friend">
    {{ outlet }}
</div>

templates/friend.hbs

<div>{{ display_name }}</div>
<div>{{ bio }}</div>
2

2 Answers

1
votes

Do you have an application template with an outlet? (I'm going to assume no, since you didn't mention it)

Additionally at some point you'll need a Friend route, or refreshes won't work.

http://emberjs.jsbin.com/ElAfAcE/3/edit

App.FriendsRoute = Ember.Route.extend({
  model: function() {
    return [{friend_id:1, color:'red'}, {friend_id:2, color:'yellow'}, {friend_id:3, color:'blue'}];
  }
});

App.FriendRoute = Ember.Route.extend({
  model: function(params){
    return this.modelFor('friends').findProperty('friend_id', parseInt(params.friend_id));
  },
  serialize: function(model){
    return {friend_id: model.friend_id}; 
  }
});
0
votes

When Ember looks for templates in a nested route, it's looking for it under this id: friends/friend

Finally, visiting /posts/new will first render the posts template, then render the posts/new template into its outlet.

http://emberjs.com/guides/routing/defining-your-routes/#toc_resources

That's the problem, but the solution is a bit more involved, because you're using compiled templates. It may be as easy as renaming the file to friends/friend.hbs, or adding it into a folder called 'friends.'