I'm trying to create a resource on my rails backend using ember.js as the frontend.
In the router.js
I have this:
//...
this.route('posts', function() {
this.route('new');
});
//...
This is app/templates/posts/new.hbs
<div>
<label>Title</label>
{{input type="text" value=model.title}}
</div>
<div>
<label>Body</label>
{{input type="text" value=model.body}}
</div>
<div>
<button {{action "save"}}>Save</button>
<button {{action "cancel"}}>Cancel</button>
</div>
app/routes/posts/new.js
looks like this:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return {};
},
actions: {
save() {
var newPost = this.get('store').createRecord('post', this.currentModel);
newPost.save().then((post) => {
this.transitionTo('post', post);
});
},
cancel() {
this.transitionTo('posts');
}
}
});
This is the post
model:
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
body: DS.attr('string'),
comments: DS.hasMany('comment')
});
When I click the save
button on the form, I get this error on the console:
POST http://localhost:4200/posts 400 (Bad Request)
further inspecting the error on the rails server side, I find this error:
ActionController::ParameterMissing (param is missing or the value is empty: post):
I don't know why the parameters from the form are not being sent with the POST request, what I'm I doing wrong?
Aucun commentaire:
Enregistrer un commentaire