views:

55

answers:

2

I have a Rails application running on Rails 2.3.9. It runs fine with ruby 1.8.7. I'm testing it with ruby 1.9.2-head right now.

The application loads fine until I try to load a page that relies on a unicode string. Then I get the infamous encoding error:

ActionView::TemplateError (incompatible character encodings: UTF-8 and ASCII-8BIT) …

It looks like the problem is that I'm getting some strings from the database as ASCII-8BIT.

I know Rails 3 works with ruby 1.9 and unicode fine. I wonder if a solution has been backported to 2.3.

So, is there any way to get unicode 2.3.9 rails apps working under ruby 1.9?

+1  A: 

If you are using mysql, use this instead of the mysql gem http://github.com/tmtm/ruby-mysql . Leave "mysql" as your database adapter in database.yml.

We are running ruby 1.9.2-rc1 with rails 2.3.8 and this solved the incompatible character encoding issue.

Jeremy
Cool. I had already gone ahead and wrote the plugin I mention in my answer. If you decide to give it a try it please leave some feedback on github.
kch
+1  A: 

So I went ahead and wrote a plugin that fixes the two underlying issues that were causing encoding problems:

  • ActiveRecord models
  • Rails built-in helpers

See UnicodeOverride plugin on GitHub.

kch