Ember Routes and Resources

Somewhat Typical Definition

This is one way to code a set of pages to:

I have a couple of notes about the Generate statements below:

1 This is a resource, which means the Ember CLI will also create a model using the same name.
Notice the resource was actually created as a route (bolded in the listing). Apparently the CLI, as of 0.2.7, isn’t smart enought yet to do that. Manually change the word “route” to “resource” and you’ll be fine OR just leave it as “route” for now because the CLI has no idea how to modify router.js when a “resource” is present.
Ember CLI will convert a plural resource to a singular model. It’s your call whether you wish to use plural or singular forms for the resource.

2 On the edit and delete routes, there is no need to specify the :id in the path because that is inherited from its parent route.

Ember CLI Generate Statement Route name in router.js file Programming route name URL Path
ember generate resource car 1 car (resource) car  
ember generate resource car/index no change to router.js car.index car/
ember generate route car/new new car.new car/new
ember generate route car/detail --path=:id detail car.detail car/12 (i.e.)
ember generate route car/detail/edit 2 edit car.detail.edit car/12/edit
ember generate route car/detail/delete 2 delete car.detail.delete car/12/delete

If you run the generated commands listed above, your router.js file will look like this:

import Ember from 'ember';
import config from './config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.route('car', function() { //Change this to a resource, or don't. ;°)
    this.route('new');

    this.route('detail', {
      path: ':id'
    }, function() {
      this.route('edit');
      this.route('delete');
    });
  });
});

export default Router;