I am very new to ember, but I've spent hours with this problem and can't solve it on my own. Here's my route (using ember-cli):
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
save: function() {
var controller = this.controller;
controller.get('model').save().then(function(account) {
console.log('account saved');
controller.transitionToRoute('accounts.index');
}, function(response) {
console.log('account NOT saved');
});
return false;
},
deleteAccount: function() {
var controller = this.controller;
controller.get('model').destroyRecord().then(function(account) {
console.log('account deleted');
controller.transitionToRoute('accounts.index');
}, function(response) {
console.log('account NOT deleted');
});
return false;
},
cancel: function() {
this.controller.get('model').rollback();
this.transitionToRoute('accounts.index');
return false;
},
}
});
I am triggering the deleteAccount action in my template (button). The interesting thing is that the code is actually deleting the record. It sends a successful delete request and the api deletes the account. But it never transitions to accounts.index. Instead it logs "account NOT deleted". If I manually go to account.index then the model isn't there any more (as one would expect). I got the code from the official ember docs. See: http://ift.tt/1FjIryj
So why is the promise always failing when the model is actually deleted? Your help would be very much appreciated!
Btw.: It is an edit route with account_id passed as param, so no need for manually defining a "model function" on the route. Just in case someone was wondering.
Aucun commentaire:
Enregistrer un commentaire