I have a serialized field called options(of type Hash) in my User model. The options field behaves like a Hash most of the time. When I convert the user object to XML, the 'options' field is serialized as a YAML type instead of Hash.
I am sending the result to a Flash client via REST. This behaviour is causing problems at the client side. Is there a way to address this?
class User < ActiveRecord::Base
serialize :options, Hash
end
u = User.first
u.options[:theme] = "Foo"
u.save
p u.options # prints the Hash
u.to_xml # options is serialized as a yaml type:
# <options type=\"yaml\">--- \n:theme: Foo\n</options>
EDIT:
I am working around this issue by passing a block to to_xml.(similar to the solution suggested by molf)
u.to_xml(:except => [:options]) do |xml|
u.options.to_xml(:builder => xml, :skip_instruct => true, :root => 'options')
end
I wondering if there is a better way.