vendredi 25 août 2017

Ember Data incompatible with Rails JSON response: Encountered a resource with an undefined type

I'm trying to set up Ember Data to talk to a Rails backend. Ember succeeds at calling the endpoint, gets both a 200 and some response data. The problem is that Ember is unable to match the response data to one of my Ember models I've made.

My model code:

export default DS.Model.extend({
  user_id: DS.belongsTo('user'),
  transcription: DS.attr('string'),
  transcription_time: DS.attr('date'),
  transcription_date: DS.attr('date'),
  recording_url: DS.attr('string'),
  state: DS.attr('string')
});

Below is an image of how the backend returns data along with the error from Ember:

enter image description here

Error: Encountered a resource with an undefined type.

I don't need to include created_at or updated_at in my Ember models do I? Also, how does Ember know to connect user_id with my User Ember model? Is that what's causing the error? I specified user_id to belongTo('user') though. Do I need to explicitly include type field in my JSON response? This doesn't seem right though.

I've read a couple of Ember guides, including their guide on models and their guide on serializers. I don't need to write a custom JSONAPISerializer, do I? Most of the guides I read did not say to do this. Any help and tips would be greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire