I'm trying to put together what I think is a pretty straightforward ember delete action (based on this example: http://discuss.emberjs.com/t/migrating-from-ember-data-0-13-to-1-0-0-beta-1-my-findings/2368) from an Index Controller and I think I must be missing something.
actions: {
deleteZone: function (zone) {
if (confirm("Are you sure you want to delete the zone?")) {
var _this = this;
zone.deleteRecord();
zone.save().then(
function () {
_this.transitionToRoute('zones.index');
},
function (error) {
zone.rollback();
}
);
}
}
}
I'm running into trouble when I try to delete a zone that has a corresponding dependency. In this case, the server (Rails 4) throws an exception and returns the following JSON:
{"status":422,"message":"Cannot delete record because of dependent projects","errors":{}}
However, while I believe the server returns the correct error, the UI seems to fail before it gets that far. If I put a debugger on the line after zone.rollback() inside the catch function I get this error:
Attempted to handle event `becameInvalid` on <App.Zone:ember1276:6> while in state root.deleted.inFlight. Called with {}.
I'm running on ember 1.4.0-beta.1, ember-data 1.0.0-beta.4 (ActiveModelAdapter) and rails 4.0.1. Any suggestions would be much appreciated, thanks!