#coding:utf-8
require 'iconv'
#Conv=Iconv.new('utf-8','gbk')
Conv=Iconv.new("GBK//IGNORE","UTF-8//IGNORE")
#Conv2=Iconv.new("UTF-8//IGNORE","GB18030//IGNORE")
class SdoEdmController < ApplicationController
before_filter:set_charset
after_filter { |c| c.response.body = Conv.iconv(c.response.body) }
def set_charset
#@headers["Content-Type"] = "text/html; charset=gb2312"
response.headers["Content-Type"] = "text/html; charset=gb2312"
end
def everyday#for mail test
yyyymmdd=params[:yyyymmdd]
logger.debug("!!!!!!!!!!!!!!!#$$$$$$$$$$$$$$$$$$$")
logger.debug(yyyymmdd)
unless yyyymmdd
@tuan=Tuan.today
else
@tuan=Tuan.day(yyyymmdd)
end
@user=User.last
#@tuan=Tuan.today
render "tuan_mail/everyday",:layout=>nil
end
end
这里的思路是在输出前将utf-8的文件代码转换为gb2312,然后在header部分设置gb2312,
同时要在meta部分设置代码为gb2312
相关的一些文章和片段
http://www.javaeye.com/topic/53673
http://kong1616.javaeye.com/blog/676101
require 'iconv'
#Conv=Iconv.new('utf-8','gbk')
Conv=Iconv.new("GBK//IGNORE","UTF-8//IGNORE")
#Conv2=Iconv.new("UTF-8//IGNORE","GB18030//IGNORE")
class SdoEdmController < ApplicationController
before_filter:set_charset
after_filter { |c| c.response.body = Conv.iconv(c.response.body) }
def set_charset
#@headers["Content-Type"] = "text/html; charset=gb2312"
response.headers["Content-Type"] = "text/html; charset=gb2312"
end
def everyday#for mail test
yyyymmdd=params[:yyyymmdd]
logger.debug("!!!!!!!!!!!!!!!#$$$$$$$$$$$$$$$$$$$")
logger.debug(yyyymmdd)
unless yyyymmdd
@tuan=Tuan.today
else
@tuan=Tuan.day(yyyymmdd)
end
@user=User.last
#@tuan=Tuan.today
render "tuan_mail/everyday",:layout=>nil
end
end
这里的思路是在输出前将utf-8的文件代码转换为gb2312,然后在header部分设置gb2312,
同时要在meta部分设置代码为gb2312
相关的一些文章和片段
- Filters for pre and post processing of the response (as methods, procs, and classes)
class WeblogController < ActionController::Base before_filter :authenticate, :cache, :audit after_filter { |c| c.response.body = Gzip::compress(c.response.body) } after_filter LocalizeFilter def index # Before this action is run, the user will be authenticated, the cache # will be examined to see if a valid copy of the results already # exists, and the action will be logged for auditing. # After this action has run, the output will first be localized then # compressed to minimize bandwidth usage end private def authenticate # Implement the filter with full access to both request and response end end
- Helpers for forms, dates, action links, and text
<%= text_field "post", "title", "size" => 30 %><br /> <%= html_date_select(Date.today) %><br /> <%= link_to "New post", :controller => "post", :action => "new" %><br /> <%= truncate(post.title, 25) %><br />
http://www.javaeye.com/topic/53673
http://kong1616.javaeye.com/blog/676101
![](http://img.zemanta.com/pixy.gif?x-id=c37e139a-5be4-8630-9424-97cdbccbc1dd)