Common feature - register user - store data in mongodb. In postman everything is ok, I can't make it good from app ui although.
My controller:
export default Ember.Controller.extend({
actions: {
addUser: function(){
let formData = {
"fullname": this.get('fullname'),
"firstname": this.get('firstname'),
"lastname": this.get('lastname'),
"email": this.get('email')
};
let newUser = this.store.createRecord('candidate',{
fullname: formData.fullname,
firstname: formData.firstname,
lastname: formData.lastname,
email: formData.email
})
newUser.save();
}
}
});
My adapter:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
namespace: 'api'
});
My model:
import DS from 'ember-data';
export default DS.Model.extend({
fullname: DS.attr('string'),
firstname: DS.attr('string'),
lastname: DS.attr('string'),
email: DS.attr('string')
});
post request is successful with 201 status. In db I see new empty document. In console I see error "SyntaxError: Unexpected token C in JSON at position 0" I guess I should have declare JSON.parse. In adapter? Making JSON.parse(newUser) doesn't help. I am newbie with ember so I guess I silly mistake but I cannot find any.
Aucun commentaire:
Enregistrer un commentaire