From d872281975b2bdcfcd06e21b55d78c8fb53ba5d1 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 9 Mar 2006 21:12:28 +0000 Subject: Fixed to_xml across the board to use nice indention, better skip_attributes workings, no type on strings, and cleaned tests [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3829 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 1203068aa8..61f7e94d89 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1504,6 +1504,20 @@ module ActiveRecord #:nodoc: @readonly = true end + # Turns this record into XML + def to_xml(options = {}) + options[:skip_attributes] = Array(options[:skip_attributes]) + options[:skip_attributes] << :type + options[:skip_attributes].collect! { |attribute| attribute.to_s } + + attributes_to_be_xmled = attributes + options[:skip_attributes].each { |attribute_name| attributes_to_be_xmled.delete(attribute_name) } + + options[:root] ||= self.class.to_s.underscore + + attributes_to_be_xmled.to_xml(options) + end + private def create_or_update if new_record? then create else update end -- cgit v1.2.3