1 安装 tiny_tds , 在 gemfile :
source 'http://ruby.taobao.org'
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter', '~> 3.2.10'
def os_family
case RUBY_PLATFORM
when /ix/i, /ux/i, /gnu/i,
/sysv/i, /solaris/i,
/sunos/i, /bsd/i
"unix"
when /win/i, /ming/i
"windows"
else
"other"
end
end
if os_family !='windows' then
gem 'therubyracer'
gem 'thin'
end
使用不同系统时,分别配置不同 gem#
2 在 database.yaml:
test ok 其中如果用了 dataserver ,host 和 port 忽略#
development:
adapter: sqlserver
model: dblib
dataserver: 127.0.0.1:1444\sql2012
#host: 127.0.0.1\sql2012
database: test
username: sa
password: xxxxx
#port: 1444
timeout: 5000
encoding: utf8
3 在初始化 rb 文件里面加入,这样数据库不区分大小写,都以小写为准:
ActiveRecord::ConnectionAdapters::SQLServerAdapter.lowercase_schema_reflection = true