jeudi 30 avril 2015

Ember get the JSON response of a POST request

I have a Ruby On Rails API and a front end in ember apart. I'm trying to add a record from ember to my api. I can see in my api logs that my request is well executed and return a json. But in my ember app i try to print that JSON response and access to those informations..

here's the code from my controller to create a record from my ember app :

export default Ember.Controller.extend({
  actions: {

    submit: function(){
      var result = this.store.createRecord("session", {email: this.get('email'), password: this.get('password')});
      var onSuccess =  function(post){

        console.log("kikou");
        console.log(post);
      };

      var onFail =  function(post){
        console.log("kikou");
        console.log(post);
      };

      result.save().then(onSuccess, onFail);
    }
  }

the JSON returned is :

{"user":{"email":"gui@hotmail.com","authentication_token":"4vLAkiM1Ro5qN2HeNogM","id":1}}

How can I access to email, authentication_token etc...? Maybe I'm doing something wrong or it is not the proper way to create a record on my rails api?

I do not want to make any ajax code in my controller otherwise I do not see any interest to use Ember.

Thank you for your help,




Aucun commentaire:

Enregistrer un commentaire