ITeye博客

rails中修改页面和应用的字符集

fourfire · 2007-01-10 05:36 · Markdown

整个应用中字符集换为gbk:1 打开Rails目录中的.app/controllers/application.rb2 增加过滤器代码before_filter :set_charsetdef set_charset@headers["Content-Type"] = "text/html; charset=gbk"end单个页面增加<%@headers["Content-Type"] = "text/html; charset=gbk"%>即可Ruby on rails

评论(1)

  1. #1 楼 · chvek · 2010-06-27 18:26

    当我在application.rb中添加:

    before_filter :set_charset
    protected
    def set_charset
      @headers['content-type'] = "text/html; charset=utf-8"
    end
    

    浏览页面的时候就出现该错误:

    You have a nil object when you didn't expect it!
    You might have expected an instance of ActiveRecord::Base.
    The error occurred while evaluating nil.[]=
    
    
    E:/rails/demo/test/app/controllers/application_controller.rb:18:in `set_charset'
    

    请问该如何解决该错误呢?

评论功能维护中,当前仅展示历史评论。