# RAILS 2.3.15 # # Since was removed from rails' xml parsing, # but not from its to_xml method, rails can't talk to an API # generated by rails, if you have serialized attributes. # This can be put in config/initializers and you should probably # upgrade to rails 3 already. Ugh. Hash::XML_FORMATTING['hash'] = Proc.new { |hash| hash.to_xml(:skip_instruct=>true, :root => "---fuck---").gsub(/\<\/?---fuck---\>\n/, "").html_safe } module ActiveRecord class XmlSerializer class Attribute def compute_type type = if @record.class.serialized_attributes.has_key?(name) @record.class.serialized_attributes[name].name.downcase.to_sym else @record.class.columns_hash[name].try(:type) end case type when :text :string when :time :datetime else type end end end end end module Builder class XmlBase < BlankSlate # this is all copied from xmlbase.rb in rails except for one line.... def method_missing(sym, *args, &block) text = nil attrs = nil sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol) args.each do |arg| case arg when Hash attrs ||= {} attrs.merge!(arg) else text ||= '' text << arg.to_s end end if block unless text.nil? raise ArgumentError, "XmlMarkup cannot mix a text argument with a block" end _indent _start_tag(sym, attrs) _newline _nested_structures(block) _indent _end_tag(sym) _newline elsif text.nil? _indent _start_tag(sym, attrs, true) _newline else _indent _start_tag(sym, attrs) # # this line! # # if you have a hash that was serialized as xml already, don't escape it here. # if args.size > 0 && args[1][:type] == :hash _text text # don't escape else text! text end _end_tag(sym) _newline end @target end end end