aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-08 01:02:45 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-08 01:02:45 +0200
commita04060fb6fe006b1dbc224263dd6c39525733c6d (patch)
tree5834291cc29dc29267ecb93a208e51a420572f41 /activemodel/lib
parentd6953cbfd3b6e06eceba715c60e288b6d7db0d49 (diff)
downloadrails-a04060fb6fe006b1dbc224263dd6c39525733c6d.tar.gz
rails-a04060fb6fe006b1dbc224263dd6c39525733c6d.tar.bz2
rails-a04060fb6fe006b1dbc224263dd6c39525733c6d.zip
Really make include_root_in_json default to true [#3770 state:resolved]
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