On 7 Oct 2008, at 02:30, Sam wrote:

>
> Why is it that...
>
> {code}
>>> myarray = ["one"]
> => ["one"]
>>> myarray.to_xml
> RuntimeError: Not all elements respond to to_xml
>       from /foo/vendor/rails/activerecord/lib/../../activesupport/lib/
> active_support/core_ext/array/conversions.rb:62:in `to_xml'
>       from (irb):94
>>>
> {code}
>
> ... however ...
>
> {code}
>>> myarray2 = [{:one => "onevalue"}]
> => [{:one=>"onevalue"}]
>>> myarray2.to_xml
> => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<records type=\"array
> \">\n  <record>\n    <one>onevalue</one>\n  </record>\n</records>\n"
>>>


In a nutshell, strings don't have a to_xml method, but hashes do.

> {code}
>
> Is there a way I can convert an array to xml without having to wrap
> each element in a hash???
>
What do you want the output to look like ?

Fred
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to