Teflon Ted
Teflon Ted

Reputation: 8846

Passing JSON from Rails 2 to Backbone.js

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?

Upvotes: 1

Views: 263

Answers (1)

maxl0rd
maxl0rd

Reputation: 1446

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.

Upvotes: 2

Related Questions