1
votes

from this post it seems that sub directories within ember controller should work.

https://github.com/ember-cli/ember-cli/issues/1219

however its not working for me .

here is my code branch like (directory cm contains a child directory views):

 /controllers/cm/views/item.js
 /routes/cm/views/item.js
 /templates/cm/views/item.js

when i try to populate the model in route using the code below i see the data but when i put the same code in controller it never gets executed.

   model: function(){

            return this.store.find('item',{id: "1"});

          }

entry in router.js is as follows:

   this.resource('cm', {path: '/cm/:id'} , function() {

                this.route('views');
                this.route('views.items', {path: '/views/items'});
       });

Clearly ember is not able to resolve the controller correctly. Not sure how to fix this ...

2

2 Answers

0
votes

That its becuase the model hook in a route works differently than in the controller.

in a route it is a method that can return a promise, the route will wait for the promise to be resolved before setting up the controller.

in the controller, it is just an attribute, which won't get executed until you getit, and even then, all you will get its a promise.

0
votes

Wat?! Subdirectories work just fine. First, I'm not sure it's the best idea to use views or items as route names, as they're both very generic, and also used in some of the ember internals and can confuse things. Declaring a model called View could very well even break things in your app.

The controller/route/template structures for your router.js will be as follows:

<controllers|routes|templates>/cm.js
<controllers|routes|templates>/cm/index.js
<controllers|routes|templates>/cm/views.js

And I'm not sure what views.items would look like, because this would probably be better suited to making views a resource instead, or using a dash in the name, in which case the route declaration would be this.route('views-items', {path: '/views/items'});

Overall, I think your router definition should look like so:

this.resource('cms', function() {
  this.resource('cm', {path: '/:cm_id'}, function() {
    this.route('views');
    this.route('views-items', { path: '/views/items' });
  });
});

This isn't meant to be a quip--I'm here to help--but I think you need to spend a little more time with Ember's routing documentation to understand the conventions that Ember is expecting for certain router definitions. Also, the ember inspector tool is a really great asset when debugging router issues: https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi