lundi 1 juin 2015

How to remove a newly created model using Ember data?

I'm implementing a view for creating a new user.

App.UserNewRoute = Ember.Route.extend({
   model : function(params) {
        return this.store.createRecord('user');
   }
});

On the UserNewController there is a method which is triggered if the user presses cancel.

App.UserNewController = Ember.ObjectController.extend({
   //... code
   actions: {
       //.. other actions
       cancel: function(){
            var model = this.get('model');
            model.destroyRecord();
            this.transitionToRoute('users');
       }
   }
});

I'm always getting the following error:

Uncaught Error: Attempted to handle event `willCommit` on <App.User:ember751:null> while in state root.deleted.saved. 

I've tried using an alternative:

  model.deleteRecord();
  model.save(); 

I get the same error.

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire