From 7e363dfc8f4950ee2aab1b5c5aeed18dedc67aae Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 15 Nov 2010 15:46:50 -0500 Subject: [PATCH] Rails include_root_in_json tips. --- index.html | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 50cade26..5ed826c6 100644 --- a/index.html +++ b/index.html @@ -786,6 +786,16 @@ account.set({access: "unlimited"}, { Override this if you need to work with a preexisting API, or better namespace your responses.

+ +

+ If you're working with a Rails backend, you'll notice that Rails' default + to_json implementation includes a model's attributes under a + namespace. To disable this behavior for seamless Backbone integration, set: +

+ +
+ActiveRecord::Base.include_root_in_json = false
+

clonemodel.clone() @@ -1465,12 +1475,17 @@ $(function(){

 def update
-  account = Account.find(params[:id])
-  account.update_attributes JSON.parse params[:model]
+  account = Account.find params[:id]
+  account.update_attributes params
   render :json => account
 end
 
+

+ One more tip for Rails integration is to disable the default namespacing for + to_json calls on models by setting ActiveRecord::Base.include_root_in_json = false +

+

emulateHTTPBackbone.emulateHTTP = true