I’ve never used xml builder in my rails 3 app, but need to start.
one of our controller methods is invoked by a remote system, and it returns only xml.
in our foo controller we have
def return_some_data
@thename = "JOHN DOE"
respond_to do |format|
format.xml
end
end
in our views/foo/return_some_data.xml.erb we have
<Response>
<Name>The name is <%= @thename %></Name>
</Response>
I would like to use xml builder instead of manually creating the xml and using erb to handle variable insertion.
I think the equivalent builder file would look like this?
xml.Response{
xml.Name(The name is @thename)
}
Also what would I rename the file return_some_data and which folder would I put it in? Also, do I need a ‘require’ or ‘include’ to start using xml builder, or is it a ruby built-in?
the view should have extension .builder
eg. views/foo/return_some_data.builderby naming it .builder, rails automatically creates you an instance of XmlMarkup
also your .builder templates are pure ruby no erb necessary