I am using ember-cli with a Rails API backend and am having some issues adding a new record.
I've set up the form and route and am able to retrieve the values from the form, but the save() does not pass these values back to the POST request for Rails, resulting in a blank record being created.
I would appreciate any assistance at all.
Adapter application.js:
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
namespace: 'api'
});
Route:
import Route from '@ember/routing/route';
export default Route.extend({
model() {
//return this.store.createRecord('book');
return {};
},
actions: {
saveBook(newBook) {
var curr = this.store.createRecord('book', {
title: newBook.title,
author: newBook.author,
genre: newBook.genre
});
alert("curr.title = " + curr.title);
curr.save();
this.transitionTo('books');
},
}
});
Template:
<h2>Add Book</h2>
<div class="layout-row">
--}}
<div class="form-horizontal">
<div class="layout-row">
<div class="layout-column flex-200">
</div>
</div>
<div class="layout-row">
<div class="layout-column flex-200">
</div>
</div>
<div class="layout-row">
<div class="layout-column flex-200">
</div>
</div>
<div class="layout-row">
<button type="submit" >Save</button>
</div>
</div>
</div>
Browser result using Ember Inspector:
{"data":{"id":"31","type":"books","attributes":{"title":null,"author":null,"genre":null}}}
Aucun commentaire:
Enregistrer un commentaire