1

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 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.