diff options
author | José Valim <jose.valim@gmail.com> | 2011-09-23 00:19:46 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-09-23 00:19:46 +0200 |
commit | 4bfbdc133a37c6046b8854d3659ba75597d1d37e (patch) | |
tree | 46e3a5eb92396b93b29f60bdc1bd87967f12c81c /activemodel | |
parent | c19c55582bf46541d0ae095ea70b65cf18aff775 (diff) | |
download | rails-4bfbdc133a37c6046b8854d3659ba75597d1d37e.tar.gz rails-4bfbdc133a37c6046b8854d3659ba75597d1d37e.tar.bz2 rails-4bfbdc133a37c6046b8854d3659ba75597d1d37e.zip |
Refactor AMo as_json.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/serializers/json.rb | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index 3c713311fd..885964633f 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -86,16 +86,12 @@ module ActiveModel # "title": "Welcome to the weblog"}, # {"comments": [{"body": "Don't think too hard"}], # "title": "So I was thinking"}]} - def as_json(options = nil) - opts_root = options[:root] if options.try(:key?, :root) - if opts_root - custom_root = opts_root == true ? self.class.model_name.element : opts_root - { custom_root => serializable_hash(options) } - elsif opts_root == false - serializable_hash(options) - elsif include_root_in_json - { self.class.model_name.element => serializable_hash(options) } + root = include_root_in_json + root = options[:root] if options.try(:key?, :root) + if root + root = self.class.model_name.element if root == true + { root => serializable_hash(options) } else serializable_hash(options) end |