<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>

Caiwangqin's blog

Focus on Life, Cloud Service, Smart Hardware, Architecture, Technic and beyond…

Ruby on Rails使用utf-8编码在Sql Server数据库中保存中文指南

2006年9月10日星期日

以下描述在Windows环境下开发RoR,使用UTF-8编码保存SQL Server中文的方法:


一、安装DBI 0.1.0,下载地址为(http://ruby-dbi.sourceforge.net)


二、安装RubyODBC 0.996,安装方法是将zip包中的文件Copy到…/ruby/1.8/i386-mswin32目录下,下载地址为(http://www.ch-werner.de/rubyodbc/)


三、在Rails App的application.rb文件下加入以下代码:


class ApplicationController < ActionController::Base  before_filter :configure_charsets   

def configure_charsets       

@headers[”Content-Type”] = “text/html; charset=utf-8″  

end

end 


四、environment.rb文件末尾中加入以下代码


require ‘odbc_utf8′ 


五、打开Windows控制面版->管理工具->数据源ODBC,创建系统DNS数据源,这里数据源名称命名为“192.168.0.10 


六、修改database.yml文件


development: 


adapter: sqlserver 


mode: odbc 


dsn: 192.168.0.10 


username: sa


password: sa


 


 


 


标签:

posted by Caiwangqin, 01:29

0 Comments:

发表评论

订阅 博文评论 [Atom]

<< 主页