Rails3, Oracle and german umlauts

Dienstag, 12. April 2011, 14:24 Uhr | roberto@vasquez-angel.de |

I’m developing an oracle based rails application with an oracle db using:

  • rails (3.0.3)
  • ruby-oci8 (2.0.4)
  • activerecord-oracle_enhanced-adapter (1.3.2)

German umlauts don’t work out-of-the box (for me) and when I start the console, I get following warning:

$> rails c
Warning: NLS_LANG is not set. fallback to US-ASCII.
Loading development environment (Rails 3.0.3)
irb(main):001:0> exit

I suppose that these two things go together.

The official oracle NLS_LANG faq: oracle.com: NLS_LANG FAQ

Solution

Connect to oracle db with sqlplus and issue following command to get the needed NLS_LANG settings:

  SELECT USERENV('LANGUAGE') FROM DUAL; 
    => GERMAN_GERMANY.WE8ISO8859P1

The trick is to set the NLS_LANG environment variable before any gems are loaded. This would be in Rails.root/config/boot.rb:

# Set up oracle parameters
ENV['NLS_LANG'] = 'GERMAN_GERMANY.WE8ISO8859P1'

Voila!