I’m facing this error since yesterday, Error: Assertion Failed: 'todo' was saved to the server, but the response does not have an id and your record does not either.
I know it should come from app/serializers/todo.js or my app/routes/application.jsbut after looking into severals forum, I have to ask the question to expert emberJs dev, as i’m a newbie :smiley:
Here’s my app/serializers/todo.js
:
import DS from 'ember-data';
export default DS.JSONSerializer.extend({
serialize: function(record, options) {
var json = this._super.apply(this, arguments); // Get default serialization
json.id = record.id; // tack on the id
return json;
}
});
And my app/routes/application.js
import Route from '@ember/routing/route';
export default Route.extend({
model(){
return this.store.findAll('todo');
},
actions: {
createtodo: function() {
var titleInput = this.get("newTitle")
var todo = this.store.createRecord('todo', {
title: titleInput,
isCompleted: false
});
this.set('newTitle', '');
todo.save();
}
}
});
The way the createtodo action is triggered app/templates/application.hbs
:
<button >Save</button>
So my objec is created but not save. When i’m looking into my ember Inspector, I see that each object I create have an ID but the title field is null or "".
This is a todoApp with an Rails-API as back and Ember as front.
Anyone see what’s wrong here ?
Aucun commentaire:
Enregistrer un commentaire