Perry Smith wrote:> module Foo
> class Bar < ActiveRecord::Base
> ...
> end
> end
>
> The to_xml for this produces <foo/bar> .... </foo/bar>
>
> The / in a tag name is not allowed. Questions:
This is what I did to work around the situation:
class Hash
class << self
private
def from_xml_with_colon_fixer(xml)
fix_colon_keys(from_xml_without_colon_fixer(xml))
end
alias_method_chain :from_xml, :colon_fixer
def fix_colon_keys(object)
case object
when Hash
puts "hi"
object.inject({ }) { |h, (k,v)| h[k.gsub(/__colon__/, ":")] =
v;
h }
when Array
object.map { |e| fix_colon_keys(e) }
else
object
end
end
end
end
module ActiveRecord
class Base
def to_xml_with_colon_fixer(options = { }, &block)
new_root = (options[:root] || self.class.to_s).gsub(/:/,
"__colon__")
options[:root] = new_root
to_xml_without_colon_fixer(options, &block)
end
alias_method_chain :to_xml, :colon_fixer
end
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---