UTF-8,Ruby on Rails under Ubuntu
Friday, October 20th, 2006 by rubypdfI installed Ruby on Rails under Ubuntu(from /var/lib/locales/supported.d/local, I know, my default charset is en_US.UTF-8 UTF-8), and create a demo, by default, mysql (table type is MyISAM)supports UTF-8. But when I input Chinese character and save to database, the output on the web is UTF-8 code, not what I want, why? After searching, I got the answer , I need modify app/controller/application.rb just like this:
class ApplicationController < ActionController::Base
before_filter :set_charsetdef set_charset
@headers["Content-Type"] = "text/html; charset=utf-8"
end
end
P.S.
My environment:
Server:
OS: Ubuntu 6.06.1 on Vmware(default charset is en_US.UTF-8 UTF-8)
Ruby: 1.8.4
Rails: 1.1.6
Mysql: 5.0.2
Mongrel: 0.3.13.4
Client:
Firefox: 1.5.0.6
IE: 6.0