Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate XML from XMLBuilder using a .xml.builder file?

I have started using xml builder templates for most of my model. I need to find a generic way to build XML outside of a render which uses the .xml.builder template instead of the generic .to_xml method provided in the model

I gather that I will have to override the default to_xml (or add a to_my_xml), but I am unable to see how to get XMLBuilder to use my .builder files.

Any ideas?

like image 298
Barrie Avatar asked Feb 01 '10 11:02

Barrie


1 Answers

Add a respond_to block in your controller so that the appropriate template is rendered according to the requested format. For example:

def show
  ...
  respond_to do |format|
    format.html # renders show.html.erb
    format.xml  # renders show.xml.builder
  end
end
like image 103
John Topley Avatar answered Sep 28 '22 20:09

John Topley