Normally when I use backbone.js I would apply this sort of patch to nest model attributes the way that Rails expects them:
Backbone.Model.prototype.toJSON = function() {
var hashWithRoot = {};
hashWithRoot[this.modelName] = this.attributes;
return _.clone(hashWithRoot);
};
App.Models.Card = Backbone.Model.extend({
modelName: 'card'
});
However, in my current project I'm using Backbone Relational, which is great, but it has its own toJSON override. The result is that I get a circular reference exception in my console:
Uncaught TypeError: Converting circular structure to JSON
Has anyone managed to successfully produce nested JSON for PUT/POST to a Rails backend with Backbone Relational?
EDIT 2:
I created a jsfiddle that shows the collections and models in question - and included some json to bootstrap the app. For some reason (maybe because I'm hungry) I can't get the fiddle to work.
Hopefully that gives a better idea of what I'm trying to do. I'm going to eat then try to fix the fiddle...
Cheers, Stu