Skip to content

Instantly share code, notes, and snippets.

@darthdeus
Created January 15, 2013 19:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darthdeus/4541354 to your computer and use it in GitHub Desktop.
Save darthdeus/4541354 to your computer and use it in GitHub Desktop.
this.resource("posts", { path: "/posts" }, function() {
this.resource("show", { path: "/:post_id" });
});
this.resource("posts", { path: "/posts" }, function() {
this.resource("post", { path: "/:post_id" });
});
this.resource("posts", { path: "/posts" });
this.resource("post", { path: "/posts/:post_id" });
@wagenet
Copy link

wagenet commented Jan 15, 2013

this.resource("posts", { path: "/posts" }, function() {
  this.route("show", { path: "/:post_id" });
});

Routes: posts, posts.index, posts.show

this.resource("posts", { path: "/posts" }, function() {
  this.resource("post", { path: "/:post_id" });
});

Routes: posts, posts.index, post, posts.index

this.resource("posts", { path: "/posts" });
this.resource("post", { path: "/posts/:post_id" });

Routes: posts, posts.index, post, posts.index


Note, posts and post are non-leaf routes. If you attempt to transitionTo them, the router will actually transition into the corresponding implicit index route.

The first two cases are useful if you have a master-detail setup. That way the posts view stays visible and you can render the post within it. If you don't have a nested setup, the last option is probably preferable. Between the first two options, I prefer the second since it provides you with what seems like more normalized naming to me.

@walter
Copy link

walter commented Jan 15, 2013

@wagenet "The first two cases are useful if you have a master-detail setup. That way the posts view stays visible and you can render the post within it."

I'm trying for this behavior now, but not getting it to work. When using linkTo 'post' post (following second route example), I always get the application template's outlet replaced rather than the outlet in the posts.index template (and thus keeping posts template stuff visible).

For this sort of nested outlets, what is required in the templates. Currently I'm not defining posts template, only posts.index. I read in a guide, I think, that I may need to define posts template with just an outlet.

@wagenet
Copy link

wagenet commented Jan 15, 2013

@walter does your posts template have an outlet in it? If not, Ember will find the closest outlet it can, which will be the one in application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment