关于在rails3中单个页面使用gb2312输出的办法
2011-03-10 10:55
204 查看
#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
相关的一些文章和片段
Filters for pre and post processing of the response (as methods, procs, and classes)
Helpers for forms, dates, action links, and text
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 endLearn more
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
相关文章推荐
- 关于在rails3中单个页面使用gb2312输出的办法
- 关于在Webservice里使用LinqToSQL遇到一对多关系的父子表中子表需要ToList输出泛型而产生循环引用错误的解决办法!(转)
- 关于ajax页面里的js方法无法使用的解决办法
- 关于mybatis的参数2个使用经验(类似于struts2的通配所有页面的action配置,xmlsq语句参数类型为基本类型时的快捷指定办法)
- java和struts使用中的一点总结--关于写在页面上的select域的选项选中后保存状态的办法!
- 关于使用struts2标签页面显示不对齐的解决办法
- rails无法使用页面缓存的解决办法
- rails无法使用页面缓存的解决办法
- 关于java response的两种页面输出方式,以及HttpUrlconnection 代理使用注意点
- 关于使用System.out.println()向控制台输出数据和使用out.println()向页面输出数据效率的问题
- rails无法使用页面缓存的解决办法
- servlet处理数据库表中所有数据,在jsp页面表格中用jst forEach输出解决办法
- UTF-8页面调用GB2312页面的JS显示乱码的解决办法
- 关于jsp页面上无法使用EL表达式的问题
- 关于使用AIDL出现空指针的解决办法
- rails中weill_paginate的paginate方法中不能使用额外参数的解决办法
- 关于透明状态栏的使用以及与软键盘冲突(导致SrollView不能滑动)的解决办法
- 关于空格和回车带来的输入输出不一致问题,使用了一个奇怪的replace
- git 使用——关于使用指令hexo d 出现一大串waring以及无法成功部署到github的解决办法
- 关于在DOMINO中使用JAVA调用JAVA受限制类的解决办法