我想从Rails应用程序连接到SQL Server没有ActiveRecord适配器。
我遵循了这个问题的答案。我安装了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
但是当我试图在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 '
据我所知,dbi
需要deprecated
宝石。当我尝试安装最新版本的deprecated
捆绑器打印:Bundler could not find compatible versions for gem "deprecated":
dbi depends on deprecated (= 2.0.1)
怎么了?如何连接到SQL Server从Rails 3没有活动记录?
这是我所做的,最终发现并阅读后:https://rails.lighthouseapp.com/projects/8994/tickets/5250-subclassesdescendants-is-not-a-symbol
-
gem uninstall deprecated
-
gem install rails-dbi
把这个放到你的gemfile中: -
bundle update
- 它会显示它重新安装弃用的,但它似乎没有造成伤害。
- 你的应用程序应该运行-至少,我的(但我使用postgres)
gem 'rails-dbi', :require => 'dbi'