ChangingThePresent
The Few, The Proud, The Pradipta 416
My Resume
Web DOC PDF
RTF ODT TXT
powered by emurse

Here’s a very easy way to change the default render format. Its not necessarily the best way for you. Consider that rendering HTML is hardcoded in the code and it is probably default in the browser/client’s Accept header.

rails/action_pack/lib/action_view/base.rb


when parameter_format.blank? && accept_format != :js
          @template_format = :html

For my usage, the best way to change was to add a method to application.rb and call it as a before filter (either by default in application.rb or as needed in each controller) (updated to a better way)


protected
def set_request_header
    xml_string = 'application/xml'
    request.instance_eval("@accepts=Mime::Type.lookup('#{xml_string}')")
    request.headers['HTTP_ACCEPT']  = xml_string
    request.env['HTTP_ACCEPT']      = xml_string
end

it’s not really “playing nice” but it works and is easy to debug and undo

Leave a Comment

back to top

micro theme by seaofclouds, and powered with Mephisto Hosting by hostingrails.com