在没有ActiveRecord的情况下连接到SQL Server

Kir*_*Kir 1 ruby-on-rails ruby-on-rails-3

我想从没有ActiveRecord适配器的Rails应用程序连接到SQL Server.

我跟着回答了这个问题.我安装了ruby-odbc gem并从ruby脚本连接到SQL Server没有任何问题.

db = DBI.connect('dbi:ODBC:ACUMENSERVER', 'login', 'password')
select = db.prepare('SELECT * from customer WHERE id = 1')
select.execute
while rec = select.fetch do
puts rec.to_s
end
db.disconnect
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在Rails控制器中执行此代码时,会发生错误:

{:forgery_whitelisted?=>"it is just an alias for 'get?' now, update your code"} is not a symbol

/home/user/.rvm/gems/ruby-1.9.2-p136/gems/deprecated-2.0.1/lib/deprecated.rb    176 in `instance_method'
/home/user/.rvm/gems/ruby-1.9.2-p136/gems/deprecated-2.0.1/lib/deprecated.rb    176 in `block in '
Run Code Online (Sandbox Code Playgroud)

据我所知,deprecated宝石是必需的dbi.当我尝试安装最新版本的deprecated打印机时: Bundler could not find compatible versions for gem "deprecated": dbi depends on deprecated (= 2.0.1)

这是怎么回事?如何在没有Active Record的情况下从Rails 3连接到SQL Server?

小智 5

这是我在最终找到并阅读之后所做的:https://rails.lighthouseapp.com/projects/8994/tickets/5250-subclassesdescendants-is-not-a-symbol

  1. gem uninstall deprecated
  2. gem install rails-dbi
  3. 把它放到你的gemfile中: gem 'rails-dbi', :require => 'dbi'
  4. bundle update
  5. 它会显示它重新安装已弃用,但似乎并没有造成伤害.
  6. 你的应用程序应该运行 - 至少,我的应用程序(但我使用的是postgres)