【问题标题】:Connect to SQL Server without ActiveRecord在没有 ActiveRecord 的情况下连接到 SQL Server
【发布时间】:2011-04-24 07:48:24
【问题描述】:

我想在没有 ActiveRecord 适配器的情况下从 Rails 应用程序连接到 SQL Server。

我关注了this question 的答案。我安装了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 gem。当我尝试安装最新版本的deprecated bundler 时打印: Bundler could not find compatible versions for gem "deprecated": dbi depends on deprecated (= 2.0.1)

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

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3


    【解决方案1】:

    这是我在最终找到并阅读此内容后所做的: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)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 2017-12-10
      相关资源
      最近更新 更多