2008年11月7日 星期五

Iconv.conv big5 轉 utf8 , response

http://twycf.com/wordpress/archives/155
http://tzangms.com/blog/programming/1314

def reply_list
html = GOOKUS_CACHE.get("nownews_reply_list_#{@nng.id}") <= get from memcache
unless html
@gookus = @nng.children.find(:all, :include => :user, :limit => limit, :order => 'created_at DESC')
html = render_to_string(:template => 'gookus/nownews', :layout => false)
GOOKUS_CACHE.set("nownews_reply_list_#{@nng.id}", html, 1.day) <= set into memcache
end

unless params[:encoding] == 'utf8'
html = Iconv.conv('big5','utf8',html) <= 把html 內容 的編碼 utf8轉成 big5
response.charset='big5' <= charset 也要改
end
response.content_type= "text/javascript"<= 是要丟一個js回去 render js
render :text => "document.write('#{escape_javascript(html)}' <= escape 過 內容
end

沒有留言: