views:

24

answers:

1

I am using Rails 2.3.4 and "to_xml" with the :methods => option, and I want to include a Base64 encoded thumbnail image. Is there any way I can specify that that method needs to be wrapped in a cdata tag?

Example:

render :xml => @items.to_xml( :include => [:photos,:comments], :methods => [:encoded_thumb]) { |xml| xml.tag! 'total-entries', @items.total_entries xml.tag! 'per-page', @items.per_page } }

A: 

A simple workaround would be :methods => [:encoded_thumb_cdata], and wrap that method in your model.

Andrew Vit
I tried that, but it escapes the cdata tag so I end up with this type of thing: <cdata> Am I missing something?
Gordon Isnor
Yeah, I hadn't thought about that... Hmm. that's a question that deserves a +1.
Andrew Vit