0

I am currently struggling to get on board with Ember.js and I bumped into an issue with my current routes design, they have nesting URLs, however there are no nesting templates, so their configuration looks like this:

 this.resource('customer', { path: '/Customer/:id' });
 this.resource('employees', { path: '/Customer/:id/Employees' });

Now, at Customers/:id (after submit action) a new Customer instance is created in DS.store and a set of empty Employee objects are added, as well, into the DS.store.

The problem is transitioning from 'customer' to 'employees', the 'employees' template is not actually rendered, 'customer' template is maintained. The last log message is "Attempting transitioning to employees'.

Could you please give me a hint what might be the problem?

ice
  • 7
  • 1

1 Answers1

0

Because of your router, Employees route does not know what its parent route is. Although you defined the path in this hierarchy, you should be using nested routes (resources).

 this.resource('customer', { path: '/customer/:id' }, function() {
    this.route('employees', {path: '/employees'});
 });
Microfed
  • 2,832
  • 22
  • 25
Dejan Biljecki
  • 595
  • 1
  • 5
  • 26
  • I hoped to be able to have nested URLs without nested routes, since my templates aren't nested, however it seems unlikely to pull this off. @Microfed – ice Oct 09 '14 at 10:10
  • @ice Routes and templates are closely related to each other. You could override Route.renderTemplate method (http://emberjs.com/guides/routing/rendering-a-template/) to change how data will be displayed inside route, of course. But it could lead to less maintainable code. :) – Microfed Oct 09 '14 at 10:17
  • @Microfed can you please detail why route should be used instead of resource? What is the unexpected behavior in routing process? It seems to me, that it's quite difficult to separate this approach of doing things because it's a simple convention and doing it because it's the right thing to do. Here I am referring to the whole "You should use this.resource for URLs that represent a noun, and this.route for URLs that represent adjectives or verbs modifying those nouns." Specifically, I suppose it relates to what model is passed to that route. – ice Oct 09 '14 at 10:46
  • @ice this.resource could be used, but you need to prefixed resource's name to build really nested structure (`this.resource('customer.employees'`) in your case. You can find more detailed explanation here: http://stackoverflow.com/a/14976499/614425 – Microfed Oct 09 '14 at 11:11