On Saturday, March 3, 2012 9:27:58 AM UTC-5, Dheeraj Kumar wrote:
>
> Rodrigo has made a very important point about which list to use.
>
> How do to X with rails -> rubyonrails-talk
> How rails does X -> rails-core
>
I'm pointing out something that changed, and would break my project if I
upgrade, in ActiveResource which I believe stems from an ActiveResource fix
to a problem caused by something that changed in ActiveModel regarding
include_root_in_json.
This might be the wrong forum, but this is my fix:
module ActiveResource
class Base
self.include_root_in_json = false
end
module Formats
module JsonFormat
def decode(json)
ActiveSupport::JSON.decode(json)
end
end
end
end
module ActiveModel
module Serializers
module JSON
def as_json(options = nil)
hash = serializable_hash(options)
if include_root_in_json
custom_root = options && options[:root]
hash = { custom_root || self.class.model_name.element => hash }
end
hash
end
def from_json(json)
hash = ActiveSupport::JSON.decode(json)
hash = hash.values.first if include_root_in_json
self.attributes = hash
self
end
end
end
end
I don't use ActiveRecord, so I don't know the full ramifications of using
that patch above. But it does make ActiveResource work again as I explore
my upgrade to 3.2.* .
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/3cEcrOfnG5UJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.