在application控制器中加入如下代码
# 将set_charset方法定义成一个过滤器
before_filter :set_charset
# 设置字符集
def set_charset
@headers["Content-Type"] = "text/html; charset=gb2312"
@response.headers["Content-Type"] = "text/html; charset=gb2312"
suppress(ActiveRecord::StatementInvalid) do
ActiveRecord::Base.connection.execute 'SET NAMES gb2312'
end
end