Where should I define a `save` action?

Absent any special circumstances, I put the ‘save’ action on the controller. For instance:

// controllers/ThingsNewController.js
App.ThingsNewController = Ember.Controller.extend({
    actions: {
        'save': function () {
            var model = this.get('content');
            
            model.save().then(function () {
                // transition wherever
            }, function () {
                // display error message
            });
        }
    }
});

he told me that if an action causes data to be set for the next page or causes the page to transition

I dunno about that…what does “causes data to be set for the next page” mean? If the controls for manipulating data are only on one template then it seems natural to me to put them on the controller for that template. If the data in question could be manipulated from multiple templates then I could see a refactoring argument because the CRUD actions could be written once and put on the ApplicationRoute or something, but I don’t even like that.

Sorry if that’s a little incoherent, I’m a bit tired; please respond with more questions if you are still confused and I’ll clarify. Also, for the record, these are not iron clad rules I’m mentioning, but they are the best practice on the Ember projects on which I worked.

1 Like