to_xml for Foo::Bar active records

20 / 20 hind sight, I would probably do things different today but I have most of my active record classes under different parent classes. For example:

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:

1) Is this a bug? 2) If so, suggestion of what to convert it to?

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