ChangingThePresent
The Few, The Proud, The Pradipta 416
CV

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

4 Comments

da best. Keep it going! Thank you
Hi, very nice post. I have been wonder'n bout this issue,so thanks for posting
Great post! I'll subscribe right now wth my feedreader software!
Hi. I like the way you write. Will you post some more articles?

Leave a Comment

back to top

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