I am creating an app in Rails and Ember.js. I have the following:
models/post.js
App.Post = DS.Model.extend({
title: DS.attr('string'),
param: DS.attr('string')
});
routes/posts.js
App.PostsIndexRoute = Em.Route.extend({
model: function() {
return this.store.findQuery('post');
}
});
// Esto hace falta?
App.PostsShowRoute = Em.Route.extend({
serialize: function(model) {
return {
post_id: model.get('param')
};
}
});
router.js
App.Router.reopen({
location: 'history'
});
App.Router.map(function() {
this.resource('posts', function() {
return this.route('show', {
path: '/:post_id'
});
});
});
store.js
App.Store = DS.Store.extend({
adapter: DS.RESTAdapter.reopen({
namespace: 'api'
})
});
templates/posts.hbs
{{outlet}}
template/posts/index.hbs
<ul>
{{#each controller}}
<li>{{#linkTo "posts.show" this}}{{title}}{{/linkTo}}</li>
{{/each}}
</ul>
When I visit localhost:3000/posts I get a list with posts, my database has 7 posts, and in this view ember.js show 7(li) element but with the last post element.
My database has: post1, pos2, post3, post4, post5, post6, post7 View show: post7, post7,post7, post7, post7,post7,post7
Any idea?