dimanche 29 novembre 2015

Ember data route with handler and api call in different location

Im new to Ember development and trying to build an Ember app using Ember data which connects to an API.

My API in the location http://localhost:3000/api/panelists returns

{  
   "panelists":[  
      {  
         "id":1,
         "secret":"",
         "isDisabled":"false",
         "disabledAt":"null",
         "isLocked":"false",
         "isSecretExpired":"false",
         "invalidAuthCount":"0",
         "givenName":"Sma",
         "middleName":"na",
         "surname":"ran",
         "avatarMimeType":"JPEG",
         "avatarFilePath":"/home/sample.jpeg",
         "createdAt":"2015-11-27T12:17:05.000Z",
         "isDeactivated":"false"
      }
   ]
}

Now in my Ember App, the model handler for this case is in the following location, App_Root/app/panelists/model.js

The specific required route is in the following path, App_Root/app/directory/route.js

Now, how do I hit the API http://localhost:3000/api/panelists with model App_Root/app/panelists/model.js and with the route App_Root/app/directory/route.js?

Current Implementation: route.js

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.store.findAll('panelists');
  },
});

Getting the following error in browser:

WARNING: Encountered "panelists" in payload, but no model was found for model name "panelist" (resolved model name using golf-digest-panelists@serializer:-rest:.modelNameFromPayloadKey("panelists"))

Error while processing route: directory Assertion Failed: You must include an 'id' for undefined in an object passed to 'push' Error: Assertion Failed: You must include an 'id' for undefined in an object passed to 'push'
    at new Error (native)
    at Error.EmberError (http://localhost:4200/assets/vendor.js:24738:21)
    at assert (http://localhost:4200/assets/vendor.js:14639:13)
    at Object.assert (http://localhost:4200/assets/vendor.js:22040:34)
    at ember$data$lib$system$store$$Service.extend._pushInternalModel (http://localhost:4200/assets/vendor.js:72829:15)
    at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:72815:34)
    at http://localhost:4200/assets/vendor.js:67700:17
    at Object.Backburner.run (http://localhost:4200/assets/vendor.js:9710:25)
    at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:4200/assets/vendor.js:73042:33)
    at http://localhost:4200/assets/vendor.js:67697:15

Thanks in advance for the help




Aucun commentaire:

Enregistrer un commentaire