Hello! I’m a relatively new Ember developer. My understanding of how Ember works is that the route’s primary job is to load a model, template, and controller (the model through the
model hook, the others by naming convention if not otherwise specified); the model’s job is to store persistent state; the template’s job is to create the user interface; and the controller’s job is to handle user interactions. I always define my actions on a controller.
However, I was recently playing around with ember-flash-message, and in a discussion with the author in a Github issue, he told me that if an action causes data to be set for the next page or causes the page to transition, it should be defined on the route. This vaguely makes sense to me, but I’ve never seen anything about it in the Ember guides or in anything else I’ve read about Ember.
So, first, is this indeed the generally-recommended practice?
And if so, second, why? What advantage does this give over defining all of the actions in a single place?
Two things make me dislike the ability to define actions in multiple places: when I come to a new Ember project and I see an action in a template, I need to check two places to figure out where it’s defined; and if I ever change an action from staying on the same route to moving to a new route, I need to move it from my controller to my route. Both of these feel like unnecessary work and confusion.
But I’m new to Ember and have only used it in small apps. I could totally be missing something here, and would love to learn from the perspective of folks with more experience.