简体   繁体   中英

Passing proper JSON objects to Ember.js from Rails

I'm using ember-rails (0.13.0), ember-data-source (0.13), and ember-source (1.0.0.rc6.2).

In my Rails controller, I have:

respond_to :json, :html

def index
  @organizations = Organization.approved.limit(25)
  respond_with @organizations
end

On the client-side, I've got this model:

Whistlr.Organization = DS.Model.extend
  name: DS.attr('string')

And this organizations template:

ul
  each organization in model
    li = organization

This renders a list of:

<Whistlr.Organization:ember335:null>

It looks like the organizations are not being properly set by the model. I'm not sure what could be causing this, but my best guess is that the JSON is improperly structured:

{"organizations":[{"organizations":{"name":"West-Nikolaus","id":null,"image":{"url":null}}},{"organizations":{"name":"Ward LLC","id":null,"image":{"url":null}}}, . . . ]}

Note that each organization is nested with an "organizations" hash which is in turn nested inside another "organizations" hash. I'm assuming the double nesting isn't suppose to happen. Any idea what's going on?

您是否查看了ActiveModelSerializers ,默认情况下,Rails不会呈现Ember-Data想要的确切格式,但是AMS已经从头开始设计为开箱即用的ember。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM