Emberjs + data + rails - Uncaught TypeError: Cannot call method 'map' of undefined

ember-data, ember.js, ruby-on-rails

Solution

I had the exactly same problem. What solved it for me was adding the root node when rendering the JSON in the `index` action in my controller. That meant changing this line:

format.json { render json: @things }

to this:

format.json { render json: { things: @things }}

That's because Ember-data requires the root node in the JSON object, but Rails doesn't include it by default.

I hope that helps.

Problem

When I am trying to load data from rails db with emberjs + ember data I am getting this error Uncaught TypeError: Cannot call method 'map' of undefined Here's the coffescript code: ``` window.Cosmetics = Ember.Application.create Cosmetics.store = DS.Store.create revision: 4 adapter: DS.RESTAdapter.create bulkCommit: false Cosmetics.admin_user = DS.Model.extend({ name: DS.attr('string') email: DS.attr('string') }); Cosmetics.view = Ember.View.extend templateName: 'ember/views/aaa' Cosmetics.admin_user.reopenClass url: 'admin/user' Cosmetics.store.findAll(Cosmetics.admin_user) ``` Controller gets proper JSON data. I've tried mapping the code from the examples found over the internet but nothing helped. Any ideas? I guess I'm doing sth wrong. Thanks in advance for any help.

Original source