Setting the request content type in Rails

To set the content type and character set of your responses of your Rails applicaiton, add this to your Application Controller (/app/controllers/application.rb):

class ApplicationController < ActionController::Base
  before_filter :set_content_type
  def set_content_type
    @headers["Content-Type"] = "text/html; charset=utf-8" 
  end    
end

This can obviously be set in any other controller if you need special contenttypes, for example for a feeds controller:

class FeedsController < ApplicationController
  before_filter :set_content_type
  def set_content_type
    @headers["Content-Type"] = "text/xml; charset=utf-8"
  end
end