aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-06-08 00:10:11 -0400
committerMikel Lindsaar <raasdnil@gmail.com>2010-06-08 00:10:11 -0400
commite404490f9bae102f8c7126917d59568e6d1fef79 (patch)
tree34a4fd7517026ab23498e7d2301f27ebd75cdee2 /activemodel/lib
parent80a044edb663e6bc619b0755e30f9db10e37e9e8 (diff)
parent8d576b51a12fdb19e3993f3678ec64b2ea60fada (diff)
downloadrails-e404490f9bae102f8c7126917d59568e6d1fef79.tar.gz
rails-e404490f9bae102f8c7126917d59568e6d1fef79.tar.bz2
rails-e404490f9bae102f8c7126917d59568e6d1fef79.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/serializers/json.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb
index ffdfbfcaaf..90305978c4 100644
--- a/activemodel/lib/active_model/serializers/json.rb
+++ b/activemodel/lib/active_model/serializers/json.rb
@@ -1,5 +1,5 @@
require 'active_support/json'
-require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/class/attribute'
module ActiveModel
module Serializers
@@ -10,7 +10,8 @@ module ActiveModel
included do
extend ActiveModel::Naming
- cattr_accessor :include_root_in_json, :instance_writer => true
+ class_attribute :include_root_in_json
+ self.include_root_in_json = true
end
# Returns a JSON string representing the model. Some configuration is
@@ -92,7 +93,9 @@ module ActiveModel
end
def from_json(json)
- self.attributes = ActiveSupport::JSON.decode(json)
+ hash = ActiveSupport::JSON.decode(json)
+ hash = hash.values.first if include_root_in_json
+ self.attributes = hash
self
end
end