jeudi 30 avril 2015

Ember infinite loop in rails api when updating record

I am trying to update a user using embers rest adapter and a rails api,

Every works until the user obj is processed by rails, there as infinite request loop from ember for updating and getting the updated user obj?

Please help, also I'm new to ember so if anyone spots anything that should be address, let me know... Primarily I need to get this fix. It's driving me insane.

SHOW CONTROLLER / EDIT USER FROM HERE

 export default Ember.Controller.extend({
    needs: ['application'],
    actions: {
        editUser: function() {
           var appCtrl = this.get('controllers.application');
           return appCtrl.set('confirmPassword', true);
       }
   },
   currentUser: function() {
       return this.get('controllers.application.currentUser');
   },
   passwordConfirmed: function() {
       var _this = this;
       var passwordEntered = this.get('controllers.application.passwordEntered');
       if (passwordEntered) {
           this.currentUser().then(function(user) {
               user.setProperties({
                   name: _this.get('name'),
                   email: _this.get('email'),
                   avatar: document.getElementById('file-field').files[0],
                   password: passwordEntered.password,
                   password_confirmation: passwordEntered.password
               }, null);
               user.save();
           });
       }
   }.observes('controllers.application.passwordEntered')
  });

USER MODEL

import DS from 'ember-data';

    export default DS.Model.extend({
         name: DS.attr('string'),
         email: DS.attr('string'),
         username: DS.attr('string'),
         avatar: DS.attr('file'),
         thumb: DS.attr('string'),
         password: DS.attr('string'),
         password_confirmation: DS.attr('string'),
         user: DS.hasMany('brands', {
         async: true
     });
});

APPLICATION CONTROLLER

import Ember from 'ember';

export default Ember.Controller.extend({
     needs: ['users/show'],
     confirmPassword: false,
     passwordEntered: false,
     actions: {
         invalidateSession: function() {
              this.authManagerService.endSession(this);
         },
         submitPassword: function() {
             var password = this.getProperties('password');
             this.set('passwordEntered', password);
             this.set('confirmPassword', false);
         },
         closeModal: function() {
             this.set('confirmPassword', false);
         }
     },
     currentUser: function() {
         if (this.session.get('user_id')) {
             return this.store.find('user', this.session.get('user_id'));
         }
     }.property('this.session.isAuthenticated'),
     removeMessage: function() {
          if (Ember.$('.message')) {
               this.set('messages', this.messages);
          }
          Ember.run.later(function() {
              Ember.$('.message').remove();
          }, 2000);
      }.observes('messages') 
 });




Aucun commentaire:

Enregistrer un commentaire