rails2.3页面中文乱码解决方案

来源:互联网 发布:static java 编辑:程序博客网 时间:2024/05/01 03:55

 刚学习ruby on rails不久,就碰见页面中文乱码问题。google后,大家给出的建议都是下面两步:

 

1. 在rhtml文件中head中加入<meta http-equiv="Content-type" content="text/html; charset=gb2312" />

2. 在对应的控制器中加入

    before_filter :set_charset
   

    def set_charset
        @headers["Content-Type"] = "text/html; charset=gb2312"

    end

 

但是,我加了后,出现错误,说@headers为nil。。。。

 

后面发现rails2.3版本中好像不支持这种方式,目前终于得到解决,同样是两步:

1. 在rhtml文件中head中加入<meta http-equiv="Content-type" content="text/html; charset=gb2312" />

2. 在对应的控制器中加入

    before_filter :set_charset
      
    def set_charset
       response.headers["Content-Type"] = "text/html; charset=gb2312"  
    end

原创粉丝点击