0
votes

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?

1
Can you reproduce a fiddle with this problem?Marcio Junior
@MárcioRodriguesCorreaJúnior I am using this code: github.com/heartsentwined/ember-auth-rails-demoie8888

1 Answers

0
votes

I have added a field as id in models/post.js so post will be unique. And this solve my problem. Thanks.