For our implementation, we essentially have a (extending the invoice example):
App.InvoiceFormController = Ember.ObjectController.extend(...)
App.InvoiceFormView = Ember.View.extend(...)
App.InvoiceEditController = App.InvoiceFormController.extend(...)
App.InvoiceNewController = App.InvoiceFormController.extend(...)
...
In my original example, however, I included nested actions inside these “new” and “edit” routes:
- /posts/new/photo
- /posts/5/edit/photo
Our ‘posts’ have the ability to add/edit different types of media: photos, videos, etc. Originally I was wanting to have these (toggable) media forms available via routes. I don’t remember all of the problems that we were having, but for one, if your router looks like:
App.Router.map(function() {
this.resource('posts', function() {
this.resource('post', {path: '/:post_id'}, function() {
this.resource('edit', function() {
this.route("photo");
});
});
this.resource('new', function() {
this.route("photo");
});
});
});
Then the naming structure implies that you’d need “newPhotoRoute”, “editPhotoRoute”, etc…this didn’t bode well with me as we have more “things” then just posts. Furthermore, you can’t just {{linkTo “photo”}}, you have to {{linkTo “new.photo”}} or {{linkTo “post.new.photo”}} which is hard to do if you want to have your new and edit views share the same template.
We then tried making these routes resources:
this.resource("edit" function() {
this.resource("photo");
});
This allowed us to have “photoRoute” and could {{linkTo “photo” }} from within the new and edit views. HOWEVER, ember didn’t handle the dup’d resources with the same name well, and it linked to the first “photo” resource defined in the router, so even though we were in the “post.new” route, {{linkTo “photo”}} would create a link to “post.edit.photo”
No good. Essentially we opted to abandon using routes for these sub-actions, but it would be nice to revisit that in the future.