Reputation: 119
I have this structure in my routes.
this.resource('stations', function() {
this.route('view', {path: ':name'});
this.route('edit', {path: ':name/edit'});
this.route('create', {path: ':name/create'});
});
I have these controllers
App.StationsEditController = Ember.ObjectController.extend({
actions: {
editStation: function() {
//Logic for edit Station
}
}
});
App.StationsCreateController = Ember.ObjectController.extend({
actions: {
createStation: function() {
//Logic for create Station
}
}
});
Please can you tell me if this is good practice?
Also I would like to just use one controller called stations with a list of my actions that all of my views within that controller can call? For Example: -
App.StationsController = Ember.ObjectController.extend({
actions: {
createStation: function() {
//Logic for create Station
}
editStation: function() {
//Logic for create Station
}
}
});
Open to ideas about this scenario.
Thank you.
Upvotes: 1
Views: 80
Reputation: 37369
The way you have your controllers set up is considered the norm, so yes, it's good practice. :)
However, combining the actions in a single controller won't work like that. Actions have a specific bubbling path. They try the route's controller first, then the route, then they bubble up the route hierarchy. They do not bubble up the controller hierarchy. So if you wanted to put the actions together like that, you'd have to define the actions in your StationsRoute
, not your StationsController
.
Upvotes: 1