开发者

Ruby 1.9, Rails 2.3.9 and unicode characters in database and erb views, still a no go?

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::Templa开发者_开发知识库teError (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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜