aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array/conversions.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index faa995bc9c..6f83231487 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -28,9 +28,14 @@ module ActiveSupport #:nodoc:
def to_xml(options = {})
raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }
- options[:root] ||= all? { |e| e.is_a? first.class } ? first.class.to_s.underscore.pluralize : "records"
- xml = options[:builder] || Builder::XmlMarkup.new
- xml.__send__(options[:root]) { each { |e| e.to_xml(:builder => xml) } }
+
+ options[:root] ||= all? { |e| e.is_a? first.class } ? first.class.to_s.underscore.pluralize : "records"
+ options[:indent] ||= 2
+ options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
+
+ options[:builder].instruct! unless options.delete(:skip_instruct)
+ root = options.delete(:root)
+ options[:builder].__send__(root) { each { |e| e.to_xml(options.merge({ :skip_instruct => true })) } }
end
end
end