nullnullnull
nullnullnull

Reputation: 8189

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?

Upvotes: 1

Views: 465

Answers (1)

Bradley Priest
Bradley Priest

Reputation: 7458

Have you looked into ActiveModelSerializers, by default Rails doesn't render the exact format that Ember-Data wants, however AMS has been designed from scratch to work out of the box with ember.

Upvotes: 3

Related Questions