Formatting Rabl for Ember or Mapping Ember to Rabl? Formatting Rabl for Ember or Mapping Ember to Rabl? json json

Formatting Rabl for Ember or Mapping Ember to Rabl?


Found a solution. My index.json.rabl looked like this:

collection @paintings extends 'paintings/show'

Now it looks like this:

collection @paintings => :paintingsextends 'paintings/show'


You can extend DS.RESTSerializer and change extract and extractMany. The following is merely a copy and paste from the serializer I use in .NET, for the same scenario:

window.App = Ember.Application.create();var adapter = DS.RESTAdapter.create();var serializer = Ember.get( adapter, 'serializer' );serializer.reopen({    extractMany: function (loader, json, type, records) {        var root = this.rootForType(type);        root = this.pluralize(root);        var objects;        if (json instanceof Array) {            objects = json;        }        else {            this.sideload(loader, type, json, root);            this.extractMeta(loader, type, json);            objects = json[root];        }        if (objects) {            var references = [];            if (records) { records = records.toArray(); }            for (var i = 0; i < objects.length; i++) {                if (records) { loader.updateId(records[i], objects[i]); }                var reference = this.extractRecordRepresentation(loader, type, objects[i]);                references.push(reference);            }            loader.populateArray(references);        }    },    extract: function (loader, json, type, record) {        if (record) loader.updateId(record, json);        this.extractRecordRepresentation(loader, type, json);    }});

And before you set your store, you must configure your model to sideload properly:

serializer.configure( 'App.Painting', {    sideloadAs: 'paintings'} );App.Store = DS.Store.extend({    adapter: adapter,    revision: 12});

Now you should be able to load rootless JSON payload into your app.

(see fiddle)