when I click in post title ('Test post') here and when I return to post's list I have unexpected empty record. This is a strange behaviour. I have simple construction:
Ember model (post.js):
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
slug: DS.attr('string'),
intro: DS.attr('string'),
body: DS.attr('string'),
created_at: DS.attr('date'),
updatedAt: DS.attr('date')
});
Ember routes:
this.route('posts', {path: 'blog'}, function() {
this.route('post', {path: '/:post_slug'});
});
index.js - for list
import Ember from 'ember';
export default Ember.Route.extend({
model() {
var posts = this.store.findAll('post');
return posts;
}
});
post.js - for single post
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return this.store.findRecord('post', params.post_slug);
}
});
Ember serializer:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
primaryKey: '_id',
serializeId: function(id) {
return id.toString();
},
extractCreateRecord: function() {
// do nothing
}
});
and I use RESTAdapter.
Express API:
app.get('/api/posts', function(req, res, next) {
Posts.find(function(err, response) {
posts = response;
res.json({posts: posts});
});
});
app.get('/api/posts/:url', function(req, res) {
Posts.findOne({slug:req.params.url},function(err, response){
post = response;
res.json({post: post});
});
});
Anybody can help me?
Aucun commentaire:
Enregistrer un commentaire