dockblog hamburg logo

Ruby/Rails setup in Unicode UTF8 with ferret search, mysql under debian etch with apache2

With the steps following you should get Ruby/Rails up running with Unicode (UTF8) support. I used MySQL under debian/etch and ferret for full text searching.

Configuring Linux

  1. Run ‘dpkg-reconfigure locales’ and be sure to configure de_DE.UTF-8@euro
  2. Set de_DE.UTF-8@euro as system-default

Configuring MySQL

  1. In /etc/mysql/my.cnf set ‘default-character-set = utf8′ within the [mysqld] section
  2. Set ‘default-character-set = utf8′ in [mysql] section also
  3. Set Database and Table Collation to ‘utf8_unicode_ci’. (Good introduction is available at julik.textdriven.com and at wiki.rubyonrails.org)

If you need to convert your database tables this article at marstononline.com might be helpful.

Configuring Apache2

Be sure Apache2 is running with ‘AddDefaultCharset utf-8′ in your (virtual-)server. But this should be default anyway.

Configuring your Rails Application

To be sure, set ‘encoding: utf8′ in your config/database.yml for all three databases (development, test and production).

Configuring ferret/acts_as_ferret

I am using ferret with the acts_as_ferret plugin for searching. Be sure to set the following in your config/environment.rb:

# Set this for UTF use (Umlaute)
# http://www.ruby-forum.com/topic/103360#228612
$KCODE = ‘u’
require ‘jcode’

# Ferret search plugin
ENV['LANG'] = ‘de_DE.UTF-8@euro’
ENV['LC_TIME'] = ‘C’
require ‘acts_as_ferret’

2 Responses to “Ruby/Rails setup in Unicode UTF8 with ferret search, mysql under debian etch with apache2”

  1. Jonathan Says:

    > Be sure Apache2 is running with ‘AddDefaultCharset utf-8′ in your (virtual-)
    > server. But this should be default anyway.
    > …
    > $KCODE = ‘u’
    > require ‘jcode’

    This is not needed as Rails 1.2 will have these as defaults. The locale and ENV stuff is the really important for Ferret.

  2. Kai Pier Says:

    Thanks for the hint, Jonathan!