EmberJS + Rails

时间:2013-09-19 18:26:17

标签: ruby-on-rails ember.js

我一直在努力让EmberJS和Rails运行一个简单的场景。

这就是我所拥有的(组合JS):

App = Ember.Application.create
  LOG_TRANSITIONS: true

App.Post = DS.Model.extend
  title: DS.attr 'string'
  description: DS.attr 'string'

App.StreamRoute = Ember.Route.extend
  setupController: (controller, model) ->
    controller.set 'posts', model
  model: -> @store.find('post')

App.Router.map ->
  @.route 'stream', path: '/'

以下是模板内容:

{{#each posts}}
  {{title}}
{{/each}}

以下是/posts的{​​{1}} JSON(也许这是错的?):

Post.all

我认为这样会很好,但它不太有用,当我运行它时,我得到3个帖子结果(这是多少),但列都包含空值:http://c.daryl.im/RTzO < / p>

如您所见,我也有这个错误。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您的JSON看起来不对。它应该是这样的:

{
   "posts":[
      {
         "created_at":"2013-08-15T23:48:54+01:00",
         "description":"A few months ago I helped develop these posters for research that our UX team had gathered to create personas for our customers to show who they are and who actually uses our product.",
         "id":7,
         "likes_count":1,
         "slug":"16ErQ",
         "thumb":{
            "url":"/posts/1/16ErQ/man.png",
            "medium":{
               "url":"/posts/1/16ErQ/medium_man.png"
            }
          },
          "title":"Persona Project",
          "updated_at":"2013-08-15T23:48:54+01:00",
          "user_id":1,
          "views_count":0
      },
...
]}

基本上你已嵌套posts并需要删除一个图层。