ror+mysql页面乱码问题
October 3rd, 2006 at 5:13 pm (ROR)
1.在application.rb的ApplicationController中加入charset的设置
class ApplicationController < ActionController::Base
before_filter :configure_charsetsdef configure_charsets
@response.headers[”Content-Type”] = “text/html; charset=utf-8″
# Set connection charset. MySQL 4.0 doesn’t support this so it
# will throw an error, MySQL 4.1 needs this
suppress(ActiveRecord::StatementInvalid) do
ActiveRecord::Base.connection.execute ‘SET NAMES UTF8′
end
end
end
2.如果还不行,修改mysql的字符集:
- 关闭mysql服务:
sudo /etc/init.d/mysql stop
- 敲入命令行:
sudo vim /etc/mysql/my.cnf
- 在[mysqld]后输入:
default-character-set=utf8
- 重启mysql服务: