`
tjcjc
  • 浏览: 21562 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

rails中文乱码

阅读更多
在使用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,可是我测试下来的结果是,可以正常使用。

除此之外 要在layout/application 中加入

    <META http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics