This project is archived and is in readonly mode.

#6043 ✓invalid
Charles

ActiveRecord and to_xml function error

Reported by Charles | November 23rd, 2010 @ 03:59 AM

LOCAL GEMS

abstract (1.0.0)
actionmailer (3.0.3)
actionpack (3.0.3)
activemodel (3.0.3)
activerecord (3.0.3)
activeresource (3.0.3)
activesupport (3.0.3)

ruby 1.9.2dev (2010-07-11 revision 28618) [x86_64-linux]

see below operate

[zheng.cuizh@localhost linux]$ irb irb(main):001:0> require 'active_record'
=> true

Array.to_xml is not correct.

irb(main):003:0> [{:id=>-1, :name=>"env1", :path=>"/home/zheng.cuizh/demo/demo/portal/../data/ENV/env1", :ctime=>"2010-11-10 19:22:45 +0800", :mtime=>"2010-11-10 19:22:45 +0800"}, {:id=>-1, :name=>"env2", :path=>"/home/zheng.cuizh/demo/demo/portal/../data/ENV/env2", :ctime=>"2010-11-10 19:22:45 +0800", :mtime=>"2010-11-10 19:22:45 +0800"}, {:id=>-1, :name=>"env3", :path=>"/home/zheng.cuizh/demo/demo/portal/../data/ENV/env3", :ctime=>"2010-11-10 19:22:45 +0800", :mtime=>"2010-11-10 19:22:45 +0800"}].to_xml
NoMethodError: undefined method `to_xml' for #<Array:0x000000146d59e8>
        from (irb):3
        from /usr/local/ruby-1.9.2/bin/irb:12:in `<main>'

next code ActiveRecord::Base.new will execute with error obviously,

but it must be execute before use to_xml()

irb(main):006:0> ActiveRecord::Base.new

ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished
        from /usr/local/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:316:in `retrieve_connection'
        from /usr/local/ruby-1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'

irb(main):007:0> 
irb(main):008:0* [{:id=>-1, :name=>"env1", :path=>"/home/zheng.cuizh/demo/demo/portal/../data/ENV/env1", :ctime=>"2010-11-10 19:22:45 +0800", :mtime=>"2010-11-10 19:22:45 +0800"}, {:id=>-1, :name=>"env2", :path=>"/home/zheng.cuizh/demo/demo/portal/../data/ENV/env2", :ctime=>"2010-11-10 19:22:45 +0800", :mtime=>"2010-11-10 19:22:45 +0800"}, {:id=>-1, :name=>"env3", :path=>"/home/zheng.cuizh/demo/demo/portal/../data/ENV/env3", :ctime=>"2010-11-10 19:22:45 +0800", :mtime=>"2010-11-10 19:22:45 +0800"}].to_xml
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<objects type=\"array\">\n  <object>\n    <id type=\"integer\">-1</id>\n    <name>env1</name>\n    <path>/home/zheng.cuizh/demo/demo/portal/../data/ENV/env1</path>\n    <ctime>2010-11-10 19:22:45 +0800</ctime>\n    <mtime>2010-11-10 19:22:45 +0800</mtime>\n  </object>\n  <object>\n    <id type=\"integer\">-1</id>\n    <name>env2</name>\n    <path>/home/zheng.cuizh/demo/demo/portal/../data/ENV/env2</path>\n    <ctime>2010-11-10 19:22:45 +0800</ctime>\n    <mtime>2010-11-10 19:22:45 +0800</mtime>\n  </object>\n  <object>\n    <id type=\"integer\">-1</id>\n    <name>env3</name>\n    <path>/home/zheng.cuizh/demo/demo/portal/../data/ENV/env3</path>\n    <ctime>2010-11-10 19:22:45 +0800</ctime>\n    <mtime>2010-11-10 19:22:45 +0800</mtime>\n  </object>\n</objects>\n"

now to_xml is work well

maybe some functions or status need initialize in ActiveRecord::Base.new,
but some time I just need use to_xml or to_json not ActiveRecord::Base.
please give me some advise.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages