lundi 11 décembre 2017

Put data in ember store and mirage

I am pushing my data in a controller to the ember store like this:

    this.get('store').pushPayload({
        "user": [
            {
                "id":2,
                "name":this.get('name'),
                "passwort":this.get('admin')
            }
        ]
      });

This works temporally fine but after a reload on a route which uses findAll to get all users from mirage the new user is deleted out of the store. So is there any possibility to hold the new user into the ember store or to push the new object into the mirage database? I´ve tried to send a post-request on my own like this:

$.ajax({
  cache:false,
  type: 'POST',
  url: "api/test",
  data: myData,
  contentType: "application/json",
  success:  function(data) {            
  //
    }
  });

But for now there occurs an error in the console saying :

Mirage: Your Ember app tried to POST 'api/test', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?

My config.js part:

this.post('/test', function(schema, request) {
    console.log('foo');
  });




Aucun commentaire:

Enregistrer un commentaire