Forum: Ruby on Rails Rendering all the elements when calling Array#to_xml

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pat M. (Guest)
on 2007-02-22 01:29
(Received via mailing list)
When I call to_xml on an array, I want it to get the XML for all the
elements in it.  I've defined to_xml in my class.

>> r.to_xml
=> "<video><id>1</id><views>2</views></video>"
>> a = [r]
=> [#<StatisticsReport:0x3259f38 @video_id=1, @views=2>]
>> a.to_xml
=> "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n<statistics-reports>\n</statistics-reports>\n"

As you can see, I've got an array, with the lone element responding to
to_xml.  But when I call to_xml on the array it doesn't include the
element's XML.  So how do I get it to render the element's XML as
well?

Pat
Pat M. (Guest)
on 2007-02-22 08:00
(Received via mailing list)
On 2/21/07, Pat M. <removed_email_address@domain.invalid> wrote:
>
> As you can see, I've got an array, with the lone element responding to
> to_xml.  But when I call to_xml on the array it doesn't include the
> element's XML.  So how do I get it to render the element's XML as
> well?
>
> Pat
>

I figured it out, and wrote an explanatory blog post at
http://evang.eli.st/blog/2007/2/22/my-rails-gotcha...
This topic is locked and can not be replied to.