Connect to SQL Server without ActiveRecord
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
gem uninstall deprecated
gem install rails-dbi
- Put this into your gemfile:
gem 'rails-dbi', :require => 'dbi'
bundle update
- It will show that it re-installs deprecated, but it did not seem to cause harm.
- Your app should run - at least, mine does (but I am using postgres)
精彩评论