20
votes

From official guides:

If the controller does not implement a method with the same name as the action in its actions object, the action will be sent to the router, where the currently active leaf route will be given a chance to handle the action.

So what are pros & cons of defining actions methods in controller and defining actions methods in route? As i can see guides doesn't talk about that. Defining in controller can be "faster" in sense of preventing action bubling.

1

1 Answers

31
votes

Good question, although perhaps not an ideal fit for the SO format.

The simple answer is, put routing-related actions in the router, and controller/model-related actions in the controller.

If you find yourself calling this.controllerFor in the router action, or this.get('target') in the controller action, there's a good chance you've misplaced the action.

Transition-related actions are often a good choice for putting in the route. Actions such as modifying or saving a model likely belong in the controller.

Remember that actions bubble up from the leaf routes to parent routes. So if you want to define an action that applies to a group of children routes, it makes sense to put that in the parent route.