mardi 24 novembre 2015

Ember- update a model using updateRecord with values coming from the controller

In my signup.js route, I'm using the code below to fetch values from my signup.js controller, and then save a new record on the user model. It works fine.

actions: {
  save: function() {
    var userName = self.controller.get('userName');
    var userEmail = self.controller.get('userEmail');
    var userHeight = self.controller.get('userHeight');

    var user = this.store.createRecord('user', {
      name: userName,
      email: userEmail,
      info: {
        height: userHeight,
      },
    });
    user.save();
  },
}

Now I need to update the record from the edit-account.js route. The values coming from the controller will have been updated by the end user.

The additional field 'securityToken' needs to be included for security reasons (The end user must also fill this in).

actions: {
  save: function() {
    var user = this.get('model.user');
    var userEmail = self.controller.get('userEmail');
    var userHeight = self.controller.get('userHeight');
    var securityToken = self.controller.get('securityToken');
    
    this.store.updateRecord('user', {
      name: userName,
      email: userEmail,
      info: {
        height: userHeight,
      },
      confirm_user: securityToken,
    });
    user.save();
  },
}

I can't work out the correct way of doing this- I've tried many variations on the above, but they all give the error 'store is not defined'.

Is it possible to update an existing record with this kind of pattern?

Many thanks




Aucun commentaire:

Enregistrer un commentaire