1、首先要像下面这样在数据库中创那建表
CREATE TABLE `students` (
`id` int(11) NOT NULL default '0',
`name` char(20) NOT NULL default '',
`tel` int(15) NOT NULL default '0',
PRIMARY KEY (`id`)
) Type=MyISAM CHARACTER SET utf8;
注意最后的Type=MyISAM CHARACTER SET utf8,指定用UFT-8
2、在environment.rb 文件中加入如下二行
$KCODE = 'u'
require 'jcode'
注意加到 do 和end的中间
3、最后在application.rb文件中加入
before_filter :configure_charsets
def 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
这样就OK了。