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

Germany’s most anticipated Web 2.0 sites - one year later

I just came across a post about Germany's most anticipated Web2.0 sites that dates back to last August. Since this is almost exactly one year ago I decided to spend half an hour of my life and conduct a completely unscientific survey to see how many of these startups are still around. For this reason I simply looked at the web sites to see if they are still here and checked if there are recent posts in the company blog to check if the site is a zombie (if there is no blog I checked the press releases). The result is: 51% are still around, 36% are gone (or not started one year later). The rest seems shaky (last blog post 6 months ago) or unknown (state cannot be determined by looking at the blog). If you consider that these startups were above the rest ("highly anticipated") and that checking if there are even online one year later is a very low barrier I was surprised by the low survival ratio. But one can regard this as positive: "quick failure" is a good stra