Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

http://www.VotanWeb.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Latin-1 for Rails

I thought that Rails was Latin 1 by default, so I was surprised to find that any Latin1 characters were garbled. Here's what I did to fix it:

   1  
   2  class ApplicationController < ActionController::Base
   3    before_filter :configure_charsets
   4  
   5    def configure_charsets
   6      if request.xhr?
   7        @response.headers["Content-Type"] ||= "text/javascript; charset=iso-8859-1"
   8      else
   9        @response.headers["Content-Type"] ||= "text/html; charset=iso-8859-1"
  10      end
  11    end
  12  
  13  end


...and it's also a good idea to explicitly specify the charset in the HTML (see below)

   1  
   2  <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS