九月
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

 

 

 

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg

Tags:

No Responses

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>