`
hallaw
  • 浏览: 59026 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

改变rails的默认to_xml方法

阅读更多

to_xml方法默认把"_"转成"-",flex里面使用起来很麻烦。所以在Application.rb里面加入下面的代码,让他不要这么干。

module ActiveSupport #:nodoc:
  module CoreExtensions #:nodoc:
    module Hash #:nodoc:
      module Conversions
        unless method_defined? :old_to_xml
          alias_method :old_to_xml, :to_xml
          def to_xml(options = {})
            options.merge!(:dasherize => false)
            old_to_xml(options)
          end
        end
      end
    end
    module Array #:nodoc:
      module Conversions
        unless method_defined? :old_to_xml
          alias_method :old_to_xml, :to_xml
          def to_xml(options = {})
            options.merge!(:dasherize => false)
            old_to_xml(options)
          end
        end
      end
    end
  end
end
module ActiveRecord #:nodoc:
  module XmlSerialization
    unless method_defined? :old_to_xml
      alias_method :old_to_xml, :to_xml
      def to_xml(options = {})
        options.merge!(:dasherize => false)
        old_to_xml(options)
      end
    end
  end
end

 

分享到:
评论
1 楼 hallaw 2007-09-14  
另一个可以默认添加的option是
:skip_types => true

在flex应用中type貌似没有什么用,反而使得xml变大

相关推荐

Global site tag (gtag.js) - Google Analytics