Ember router and controller logic

ember-old-router, ember.js

Solution

I had a few exchanges with Tilde team, and Tom Dale teached us to follow the way proposed by hvgotcodes.

But a refinement occured after a discussion with Peter Wagenet: As a reply to my interrogation, Peter & Yehuda mitigated the position we held from Tom explanations.

So I would summarize the whole picture saying:

- Behavior should be coded at a high-level in route's event handlers,

- But factorized low-level primitives may (/should?) be localized in controllers.

The reason is any processing should be scoped inside a given route, which ensure a coherent behavior of the whole app, not opening all the possible processings to any part of the app.

Problem

I am curious to know just what logic lies in which layer with respect to the new ember routing and controllers: If we take the route below as an example: ``` step1: Ember.Route.extend route: '/step1' connectOutlets: (router, event) -> exercise = WZ.Exercise.createRecord() router.get('exercisesNewStep1Controller').set 'groups', WZ.store.find(WZ.Group) router.get('exercisesNewController').connectOutlet 'step', 'exercisesNewStep1', exercise ``` My ExercisesNewStep1Controller is currently logicless: ``` WZ.ExercisesNewStep1Controller = Em.Controller.extend() ``` The recommended advice seems to be to have the route just take care of assigning the correct outlet to the correct controller with any other logic in the controller. Should I refactor my controller to something like this: ``` WZ.ExercisesNewStep1Controller = Em.Controller.extend createGroup: -> @set 'groups', WZ.store.find(WZ.Group) ``` This is a very simple example but I think the logic holds. I am a bit confused what lies where with all the layers. I think there is a small amount of overhead by having to create all these xxxController, xxxView files and coupling between them. I love ember but I just want to raise this point.

Original source