I’m trying to get my Rails app to serve XHTML content properly, with the correct content-type of application/xhtml+xml. Ideally with content negotiation so that IE users get a chance to use the site too.
Given that all the HTML generated by Rails is marked at XHTML 1.0 Transitional, I’m a bit surprised that there is no obvious option to make Rails serve markup as XHTML. I found this http://blog.codahale.com/2006/05/23/rails-plugin-xhtml_content_type/, but it seems to be for 1.1.2 and I can’t get it working properly under 2.3.8.
Have I missed something here?
Ok, I’ve got something that works now. Thanks to @danivovich for starting me in the right place. The first thing I had to do was sort out the Mime types in mime_types.rb so that HTML wasn’t aliased with XHTML:
The I just added this to my application controller:
This makes sure that XHTML is always servered as such, unless the client doesn’t accept it, or HTML has been explicitly requested. HTML is always just XHTML served as a polyglot. The @serving_polyglot variable is available in the views where any switching is needed.
This is working for me under Chrome, Safari, Firefox, Opera and IE[6-8].