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}
a.to_xml
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <visibility type=\"integer\">0</visibility>\n <code>K</code>\n <type>Activity</
\n <id type=\"integer\">1</id>\n <disposition type=\"integer
\">2</disposition>\n <description>Kahu</description>\n <projected- completed-at nil=\"true\"></projected-completed-at>\n <owner-id type= \"integer\">3</owner-id>\n <parent-id nil=\"true\"></parent-id>\n <created-at type=\"datetime\">2007-08-17T19:19:27Z</created-at>\n</
\n"
puts a.to_xml
<?xml version="1.0" encoding="UTF-8"?> <hash> <visibility type="integer">0</visibility> <code>K</code> <type>Activity</type> <id type="integer">1</id> <disposition type="integer">2</disposition> <description>Kahu</description> <projected-completed-at nil="true"></projected-completed-at> <owner-id type="integer">3</owner-id> <parent-id nil="true"></parent-id> <created-at type="datetime">2007-08-17T19:19:27Z</created-at> </hash> => 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"}
h.to_xml
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <a>1</a>\n <b>2</b>\n</hash>\n"
puts h.to_xml
<?xml version="1.0" encoding="UTF-8"?> <hash> <a>1</a> <b>2</b> </hash> => 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?
Ryan