Take a match block and add routes to a RouteRecognizer:
match("/posts").to("posts", function(match) {
match("/").to("postIndex")
match("/:id").to("showPost");
match("/edit").to("editPost");
match("/new").to("newPost");
});
match("/posts").to("postIndex");
match("/posts", function(match) {
match("/").to("postIndex");
})
// generate
router.add([{ path: "/posts", handler: "posts" }, { path: "/:id", handler: "showPost" }], { as: "posts.show" });
router.add([{ path: "/posts", handler: "posts" }, { path: "/edit", handler: "editPost" }]);
router.add([{ path: "/posts", handler: "posts" }, { path: "/new", handler: "newPost" }]);
router.generate("posts.show", { id: 1 }) // /posts/1
{{ linkTo "showPost" post }}
App.ShowPostRoute = Ember.RouteHandler.extend({
serialize: function(post) {
return { id: post.get('id'); }
},
contentForController: function(params) {
return App.Post.find(params.id);
},
setupControllers: function(post) {
this.set('controller.content', post);
},
renderTemplates: function() {
this.render('show_post', { into: 'application', outlet: 'view', controller: this.get('controller'), view: App.ShowPostView })
},
events: {
deletePost: function(post) {
var postController = this.controllerFor('post');
post.deleteRecord();
this.transitionTo('postIndex', posts);
}
});
App.PostIndexRoute = Ember.RouteHandler.extend({
contentForController: function() {
return App.Post.findAll();
},
setupControllers: function(posts) {
this.set('controller.content', posts);
}
})
App.ShowPostRoute = Ember.RouteHandler.extend({
initialSubstate: 'showingComments',
enter: function() {
this.transitionTo('showingComments');
},
substates: {
showingComments: Ember.State.extend({
renderTemplates: function() {
}
}),
showingTrackbacks: Ember.Handler.extend({
})
}
});
match("/login").to("login");
match("/").to("dashboard");
App.LoginState = Ember.State.extend({
renderTemplates: function() {
this.render('login')
}
});
App.LoggingInState = Ember.State.extend({
renderTemplates: function() {
this.render('loggingIn');
// or do nothing, and use the loginController to control the login UI
},
events: {
loggedIn: function() {
this.transitionTo("dashboard");
},
failure: function() {
this.controllerFor("login").set("failure", true);
this.transitionTo("login");
}
}
});
App.LoginHandler = Ember.RouteHandler.extend({
substates: {
login: App.LoginState,
loggingIn: App.LoggingInState
}
});
Under the heading Route Handlers, how are you accessing the posts variable in the deletePost function?
@wycats btw, thank you for all the open-source contributions. i've been a beneficiary of your work for some time now, and I just wanted to express my gratitude for it.