XHTML Content Type plugin

Plugin details

xhtml_content_type allows you to set the default MIME type for rendered .rhtml views to application/xhtml+xml if the client supports it, and only falling back to text/html for older clients.

Websitehttp://blog.codahale.com/2006/05/23/rails-plugin-xhtml_content_type/ Repositoryhttp://svn.codahale.com/xhtml_content_type/ Author Coda Hale Tags xhtml, mime LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.codahale.com/xhtml_content_type/

xhtml_content_type is super easy to use. Add the method +sends_xhtml_with_correct_content_type+ to a specific controller, or to ApplicationController to make all controllers send XHTML properly:

  class ApplicationController < ActionController::Base
    sends_xhtml_with_correct_content_type
  end


+sends_xhtml_with_correct_content_type+ also accepts standard filter-style conditions, if you need them:

  class MySpecialController < ApplicationController
    sends_xhtml_with_correct_content_type :except => [:seriously_weird_action]
  end

  class MyOtherSpecialController < ApplicationController
    sends_xhtml_with_correct_content_type :only => [:the_only_regular_action]
  end


You can also explicitly specify an XHTML content type using this plugin:

  def xhtml_only_action
    render :content_type => :xhtml
  end


If you're declaring the content type in a element as well, you should do something like this:

  < meta http-equiv="content-type" content="<%= controller.preferred_content_type %>; charset=UTF-8" />

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago