I have Rails 1.1, MySql 5.0 and would like to stor text as utf8 in the db. I have changed the character set and collation in the db to utf8 and utf8_danish_ci - also checked the mysql to if its ok: show collations like "%danish%"; utf8_danish_ci utf8 203 Yes 8 I then add the following environment.rb: $KCODE = 'u' require 'jcode' och database.yml encoding: utf8 If I then restart the webserver I get: Character set 'utf8' is not a compiled character set and is not specified in the '/usr/local/mysql/share/mysql/charsets/Index' file rake aborted! Can't initialize character set utf8 (path: /usr/local/mysql/share/mysql/charsets/) First thought that I was missing the charset but it was ok. Then I removed encoding: utf8 and added the following to my application controller: before_filter :configure_charsets def configure_charsets headers["Content-Type"] = "text/html; charset=utf-8" ActiveRecord::Base.connection.execute 'SET NAMES UTF8' end This then works fine. Has anyone else encountered the same or have a solution?
on 2006-05-19 17:05
on 2006-07-28 04:36
Bam! I've been looking for a solution and this seems to have fixed everything. By default MySQL 4.1 was setup to use some weird latin encoding. I switched all the tables manually to utf-8 bin...Even after that on my main site I was getting funny characters displayed for quotes and things of that nature. This fixed it all. The weird thing is, on the back-end admin site where I'm using forms and such the data was displaying fine. I'm wondering if by default Rails sets this charset and content type when using the form helpers??? On 5/19/06, Mattias B. <firstname.lastname@example.org> wrote: > before_filter :configure_charsets > def configure_charsets > headers["Content-Type"] = "text/html; charset=utf-8" > ActiveRecord::Base.connection.execute 'SET NAMES UTF8' > end > > This then works fine. Has anyone else encountered the same or have a > solution? > > -- seth at subimage interactive http://www.subimage.com/sublog/