From_xml not working

I’m having trouble using Hash.from_xml, so I dropped into script/
console to see what was happening.

t = Trackable.find(1)
=> #<Activity:0xb707e5b0 @attributes={“visibility”=>“0”, “code”=>“K”,
“type”=>“Activity”, “disposition”=>“2”, “id”=>“1”,
“description”=>“Kahu”, “owner_id”=>“3”, “projected_completed_at”=>nil,
“parent_id”=>nil, “created_at”=>“2007-08-17 19:19:27”}>

a = t.attributes
=> {“visibility”=>0, “code”=>“K”, “type”=>“Activity”, “id”=>1,
“disposition”=>2, “description”=>“Kahu”,
“projected_completed_at”=>nil, “owner_id”=>3, “parent_id”=>nil,
“created_at”=>Fri Aug 17 19:19:27 UTC 2007}

=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n <visibility
type=“integer”>0\n K\n Activity</
type>\n <id type=“integer”>1\n <disposition type="integer
“>2\n Kahu\n <projected-
completed-at nil=“true”>\n <owner-id type=
“integer”>3\n <parent-id nil=“true”>\n
<created-at type=“datetime”>2007-08-17T19:19:27Z\n</

puts a.to_xml

<?xml version="1.0" encoding="UTF-8"?> 0 K Activity 1 2 Kahu 3 2007-08-17T19:19:27Z => nil >> Hash.from_xml(a.to_xml) => {"hash"=>nil}

That doesn’t work, but this does:

h = {‘a’ => ‘1’, ‘b’ => ‘2’}
=> {“a”=>“1”, “b”=>“2”}

=> “<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n 1\n

puts h.to_xml

<?xml version="1.0" encoding="UTF-8"?> 1 2 => nil >> Hash.from_xml(h.to_xml) => {"hash"=>{"a"=>"1", "b"=>"2"}}

I’m using Rails 1.2.3.

Am I doing anything wrong, or is from_xml not working properly?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs