Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EmberJS routing clarification

Tags:

ember.js

I'm still new to Ember.js. The Nested Resources example states the following:

URL:        /post/:post_id/comments/new
Route Name: comments.new
Controller: App.CommentsNewController
Route:      App.CommentsNewRoute

Given this:

  1. "post" is in the URL, but why is "post" not in the route name, controller or route?
  2. How would one disambiguate between new comments in a "post" and new comments in another area?
  3. I don't see a templateName option in the route creation code, so would this be set in the controller?

Thank you!

Edit: This question is about Ember Pre4.

like image 856
shs Avatar asked May 17 '26 21:05

shs


2 Answers

  1. It's because post is a resource, comments is a resource, whilst new is a route. The path for the route begins at the last resource name, in this case comments. I perceive this as a problem, as you've addressed in the second question, so I expect this to change to be PostCommentsNewController.

  2. You don't disambiguate between them at the moment, but expect this to be in pre 5.

  3. There's no need to specify a templateName unless you're inserting views manually. For /#/pets Ember will first consult App.PetsRoute, locate/instantiate App.PetsController, and instantiate App.PetsView. App.PetsView will be inserted into a template which has a data-template-name of "pets".

like image 154
Wildhoney Avatar answered May 19 '26 10:05

Wildhoney


Question 3: The TemplateName to be rendered for a route can be set by using the this.render-method documented here: http://emberjs.com/guides/routing/rendering-a-template/

like image 43
Espo Avatar answered May 19 '26 10:05

Espo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!