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