如何使用RABL强制XML输出?它将JSON呈现为默认值,效果很好。当我使用
访问我的页面时 curl -H "Accept: application/xml" -X GET (myurl)
RABL按预期呈现XML。但是,当我使用浏览器访问相同的URL时,响应是JSON。 我试过设置
ActionView::Template::Handlers::Rabl.default_format = Mime::XML
以及
render "index.rabl", :content_type => 'application/xml'
在这种情况下,rails将application / xml作为内容类型返回,但仍返回JSON。
如何在不发送application/xml
作为唯一接受标头的情况下呈现数据的XML表示形式?
答案 0 :(得分:1)
尝试在路线中添加默认格式:
get 'your/url/matcher' => 'controller#method', :defaults => { :format => :xml }
答案 1 :(得分:0)
您使用的是什么版本的Rails?我很确定你是否这样做:
respond_to do |format|
format.xml # renders rabl as xml
format.json # render rabl as json
end
但那是在Rails 2中。我确信有3个等价物。