emberjs/ember.js — pull request #1693 by dgeb (2013-01-05 23:07:32+00:00)
Title: Ember.Route.controller and other tweaks

This PR includes a number of tweaks to Ember.Route:

* It includes and extends #1663, which ensures that `renderTemplates` renders with the route's correct controller.

* It renames `setupControllers()` to `setupController()`. This method should be used to set up the route's default controller, not additional controllers used to render templates (which should be done in `renderTemplates()`). Therefore, there was no reason for the plural/singular mismatch between the method and its arguments.

* It extracts `Ember.generateController()` from `Ember.controllerFor()`, so that `generateController()` can be called independently.

* Comments were added to `Ember.Route.renderTemplates()`

* It removes `Ember.Route.lookupController()` and merges controller lookup logic into `Ember.Route.controllerFor()`

* Last but not least, it provides a simple and dynamic way to specify a route's controller: a `controller` hook.

The new `controller` hook is useful for sharing a single controller class across multiple routes. For example:

```js
App.NewPostRoute = Ember.Route.extend({
controller: function() {
return App.EditPostController;
}
});
```

Alternatively, you could choose the controller based on the context of its route. For example:

```js
App.PostRoute = Ember.Route.extend({
controller: function(model) {
if (model.isNew()) {
return App.NewPostController;
} else {
return App.EditPostController;
}
}
});
```