1
votes

How do I force XML output with RABL? It renders JSON as default, which works fine. When I access my page with

curl -H "Accept: application/xml" -X GET (myurl)

RABL renders XML as expected. However, when I access the same URL with a browser, the response is in JSON. I tried setting

ActionView::Template::Handlers::Rabl.default_format = Mime::XML

as well as

render "index.rabl", :content_type => 'application/xml'

In that case, rails returns application/xml as content type but still returns JSON.

How can I render the XML representation of my data without sending application/xmlas the only accept header?

2

2 Answers

1
votes

Try adding a default format to your route:

get 'your/url/matcher' => 'controller#method', :defaults => { :format => :xml }
0
votes

What version of Rails are you on? I am pretty sure if you do this for instance:

respond_to do |format|
  format.xml # renders rabl as xml
  format.json # render rabl as json
end

But that's in Rails 2. I am sure there is an equivalent for 3.