2

My application keeps generating the default route even though I have the route explicitly defined. I think I'm overlooking a naming convention but googling, stackoverflowing, discuss.emberjs.com'ing and plain old cursing at the computer isn't getting me anywhere yet.

app/router.js

var Router = Ember.Router.extend();    

Router.map(function(){                 
  this.resource('things', function() {
    this.route('new');                 
  });                                  
});                                    

export default Router;

app/routes/things_new.js

var ThingsNewRoute = Em.Route.extend({     
  model: function() {                       
    window.console.log('hello hello');      
    return this.store.createRecord('thing');
  }                                         
});                                         

export default ThingsNewRoute;             

Visiting http://localhost:8000/#/things/new the template renders well and there are no errors. The output from ember's logging:

generated -> route:application Object {fullName: "route:application"} ember.js:415
generated -> route:things Object {fullName: "route:things"} ember.js:415
generated -> route:things.new Object {fullName: "route:things.new"} ember.js:415
generated -> controller:application Object {fullName: "controller:application"} ember.js:415
Rendering application with default view <(subclass of Ember.View):ember267> Object {fullName: "view:application"} ember.js:415
generated -> controller:things Object {fullName: "controller:things"} ember.js:415
Rendering things with default view <Ember._MetamorphView:ember283> Object {fullName: "view:things"} ember.js:415
generated -> controller:things.new Object {fullName: "controller:things.new"} ember.js:415
Rendering things.new with default view <Ember._MetamorphView:ember293> Object {fullName: "view:things.new"} ember.js:415
Transitioned into 'things.new' ember.js:415
Ember Debugger Active

The problem is this:

generated -> route:things.new Object {fullName: "route:things.new"} ember.js:415

It shouldn't generate this because I'm defining it. Is there some file naming convention that I'm not following?

Also looking at Ember Inspector in Chrome. Under "Own Properties" under ThingsNewRoute:

routeName: things.newSend
controller: (generated things.new controller)
lastRenderedTemplate: things.new
teardownOutletViews: [ function() { ... } ]
James
  • 4,179
  • 2
  • 15
  • 22

2 Answers2

1

In ember-app-kit to get your routes picked up correctly by the resolver you have to put them in sub directories.

For example, for your use case by having a router map like:

Router.map(function(){                 
  this.resource('things', function() {
    this.route('new');                 
  });                                  
}); 

The directory structure should be:

app/
   ...
   routes/
      things/
        new.js
        ...

Because the resolver expects the route ThingsNewRoute to be found in app/routes/things/new.js

Hope it helps.

intuitivepixel
  • 23,092
  • 3
  • 53
  • 51
  • Tried this earlier and (thought) it didn't work. Tried it again after seeing your answer and, of course, it's all peachy now lol. Thanks! – James Oct 12 '13 at 17:59
0

The ThingsNewRoute should be a property of your application object. So the declaration would look like:

App.ThingsNewRoute = Em.Route.extend({
    ....
})

Replace name App with a variable to which you assigned your Ember.Application.create();

chrmod
  • 1,279
  • 10
  • 19