开发者

Connect to SQL Server without ActiveRecord

开发者 https://www.devze.com 2023-02-28 14:43 出处:网络
I want to connect to SQL Server from Rails app without ActiveRecord adapter. I followed answer for this question. I installed ruby-odbc gem and connected to SQL Server from ruby script without any pr

I want to connect to SQL Server from Rails app without ActiveRecord adapter.

I followed answer for this question. I installed ruby-odbc gem and connected to SQL Server from ruby script without any problem.

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

But when I am trying to execute this code in Rails controller, error happ开发者_运维问答ens:

{: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 '

As far as I know, the deprecated gem is required by dbi. When I tried to install the latest version of deprecated bundler printed: Bundler could not find compatible versions for gem "deprecated": dbi depends on deprecated (= 2.0.1)

What's up? How to connect to SQL Server from Rails 3 without Active Record?


Here is what I did, after finally finding and reading this: https://rails.lighthouseapp.com/projects/8994/tickets/5250-subclassesdescendants-is-not-a-symbol

  1. gem uninstall deprecated
  2. gem install rails-dbi
  3. Put this into your gemfile: gem 'rails-dbi', :require => 'dbi'
  4. bundle update
  5. It will show that it re-installs deprecated, but it did not seem to cause harm.
  6. Your app should run - at least, mine does (but I am using postgres)
0

精彩评论

暂无评论...
验证码 换一张
取 消