在使用rails+mysql的时候遇到了中文乱码的问题,google了一下,解决了,把它贴出来,防止以后又忘记了
首先在application.rb中增加utf-8的filter:
class ApplicationController < ActionController::Base
before_filter :configure_charsets
def configure_charsets
@headers[ " Content-Type " ] = " text/html; charset=utf-8 "
end
end
修改数据库的编码为utf-8
CHARSET=utf8
其中有一点要说明的是,我看到有人说,不能使用InnoDB,可是我测试下来的结果是,可以正常使用。
[color=red]除此之外 要在layout/application 中加入
<META http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">[/color]
首先在application.rb中增加utf-8的filter:
class ApplicationController < ActionController::Base
before_filter :configure_charsets
def configure_charsets
@headers[ " Content-Type " ] = " text/html; charset=utf-8 "
end
end
修改数据库的编码为utf-8
CHARSET=utf8
其中有一点要说明的是,我看到有人说,不能使用InnoDB,可是我测试下来的结果是,可以正常使用。
[color=red]除此之外 要在layout/application 中加入
<META http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">[/color]