On 2/21/07, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
>
I figured it out, and wrote an explanatory blog post at
http://evang.eli.st/blog/2007/2/22/my-rails-gotcha-custom-to_xml-in-a-hash-or-array
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---