When Backbone.js gets JSON from the server, it expects it to not have the model-name wrapper that Rails/ActiveRecord applies via the to_json call. You can disable this globally in Rails, but that would break legacy integration points I have to support. Is there an elegant solution on either side?
1 Answer
Oh, much like my answer to your other question, in this case you can override parse() on your model. This is also generalizable in a model base class if you prefer.
parse: function(response) {
return response.model_name;
},
Edited to add code.
1 Comment
maxl0rd
Parse is a one liner that takes the json object you get from the server and returns it. By default it's a no op. Just write one that returns the root object that you care about.