Skip to content

Instantly share code, notes, and snippets.

@joeytrapp
Last active December 12, 2015 01:48
Show Gist options
  • Save joeytrapp/4693660 to your computer and use it in GitHub Desktop.
Save joeytrapp/4693660 to your computer and use it in GitHub Desktop.
How to get parent route models in the child route model() method.
App.Router.map(function() {
this.resource('posts', function() {
this.resource('post', { path: '/:post_id' }, function() {
this.resource('permissions', function() { ... });
});
});
});
App.PermissionsRoute = Ember.Route.extend({
model: function() {
// need parent route model
return App.Permission.find({ post_id: parent.model.id });
}
});
// Currently I access the parent routes controller for its model like:
App.PermissionsRoute = Ember.Route.extend({
model: function() {
var post = this.controllerFor('post').get('model');
return App.Permission.find({ post_id: post.get('id') });
}
});
// But, this doesn't work when the permissions route is entered via url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment