<body>

Caiwangqin's blog

Focus on Web2.0, Business, Architecture, Agile, 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, 上午1:29

<< 主页