Skip to main content

Ruby on Rails, Unicode and Oracle

I was kind of in love with Ruby on Rails but now our relationship has hit the first bump: the infamous UTF-8 issue. In short, Ruby does not support UTF-8 (that's more or less the situation). So Rails does not either. However, my task at hand basically involves CRUD operations on a legacy (yet, UTF-8 enabled) Oracle db including German texts. Well, here's how to do that:

The first stop for Unicode in general is the wiki page on Unicode and Rails: http://wiki.rubyonrails.org/rails/pages/HowToUseUnicodeStrings

The problem with that page is that it covers the setup of Postgres and MySql-based applications, but not Oracle. In order to get that done I left my database.yml as before, but added a line to config/environment.rb:

ENV['NLS_LANG']='american_america.AL32UTF8'

This sets an environment variable (it also works if you set the variable for your Rails server process externally). I had to figure out the value of this variable by querying the database:

select * from nls_database_parameters;

For the line in environment.rb use the parameters as: (NLS_LANGUAGE)_(NLS_TERRITORY).(NLS_CHARACTERSET)

OK, I'm happy with my Rails again.

Comments

herr ernst said…
thanks so much, you saved my life!
Worth reading and i like this "COFFEE & GEMS" :)

Popular posts from this blog

Python script to set genre in iTunes with Last.fm tags

Now that I have started to seriously use iTunes I figured it might be nice to have the genre tag set in a meaningful way. Since I have a reasonably large collection of mp3s doing that manually was out of question - I wrote me a Python script to do that. There seems to be a large demand for such a functionality (at least I found a lot of questions on how to automatically set the genre tag) so maybe someone else finds the script useful. It is pasted below. General Strategy The basic idea is to use Last.fm's tags for genre tagging. In iTunes the genre tag is IMO best used when it only contains one single genre, i.e. something like "Electronica", not something like "Electronica / Dance". On the other hand dropping all but one tag would lose a lot of information, so I decided to use the groupings tag for additional information that is contained in the list of tags that an artist has on Last.fm. In the example above that would be something like "Electronica, Dan

Running the iTunes genre tagger script with OS X Automator

Due to public demand here's a little recipe how to run last post's mp3 tagger without using the command line on OS X: Open Automator Start a new "Application" project Drag the "Run Shell Script" action into the right workflow panel, set the "pass input" drop-down to "as arguments" and edit the script to (see screenshot below): for f in "$@" do /opt/local/bin/python /Users/michaelmarth/Development/Code/mp3tagger/tag_groupings.py -d "$f" done (you will have to adapt the paths to your local setup) Save the application and happily start dropping mp3 folders onto the application's icon.