将未维护的 ActiveRecord 适配器强制为 Rails 版本 6
forcing an unmaintained ActiveRecord adapter to Rails version 6
我正在开发“Advantage 数据库服务器”适配器扩展,以尝试与我有权访问(仍在使用中)的遗留数据库通信。
我已经更新了“Advantage”Gem,因此它适用于 Ruby 的 new/active 版本 https://github.com/t12nslookup/advantage and have seen that my copy of the activerecord-advantage-adapter https://github.com/t12nslookup/activerecord_advantage_adapter 适用于 ruby 1.9.3 和rails 3.2.22
我一直在尝试强制它与 rails 6 一起工作,并且通过一个简单的“ruby”脚本“需要”宝石并访问数据,但我无法在 rails 控制台获得相同的简单数据库查询。
我是 WSL 2 的 运行,如果它有什么不同的话(但我不相信。
ruby 2.7.0p0(2019-12-25 修订版 647ee6f091)[x86_64-linux]、Rails 6.0.3.3
我已将 rails6 分支添加到 activerecord-advantage-adapter github 项目。
Ruby 脚本:
jadams@Temp046317:~/code/ais-lims$ more ../testme.rb
require 'rubygems'
gem 'advantage'
gem "activerecord-advantage-adapter"
require "active_record"
ActiveRecord::Base.establish_connection(
adapter: 'advantage',
options: 'ServerType=Local|Remote; ReadOnly=True; CommType=TCP_IP; Compression=INTERNET',
database: '//172.27.176.1:6262/c$/ads/db/'
)
class Discount < ActiveRecord::Base
self.table_name = 'DISCOUNT'
self.sequence_name = :autogenerated
end
puts Discount.all.inspect
puts Discount.count
jadams@Temp046317:~/code/ais-lims$ ruby ../testme.rb
#<ActiveRecord::Relation [#<Discount >, #<Discount >, #<Discount >, #<Discount >]>
4
Rails 控制台:
jadams@Temp046317:~/code/ais-lims$ more config/database.yml
development:
adapter: 'advantage'
options: 'ServerType=Local|Remote; ReadOnly=True; CommType=TCP_IP; Compression=INTERNET'
database: '//172.27.176.1:6262/c$/ads/db/'
jadams@Temp046317:~/code/ais-lims$ more app/models/discount.rb
class Discount < ApplicationRecord
self.table_name = 'DISCOUNT'
self.sequence_name = :autogenerated
end
jadams@Temp046317:~/code/ais-lims$ rails c
Running via Spring preloader in process 728
Loading development environment (Rails 6.0.3.3)
2.7.0 :001 > puts Discount.all.inspect
Traceback (most recent call last):
1: from (irb):1
NoMethodError (undefined method `to_sym' for nil:NilClass)
2.7.0 :002 > puts Discount.count
Traceback (most recent call last):
2: from (irb):1
1: from (irb):2:in `rescue in irb_binding'
NoMethodError (undefined method `to_sym' for nil:NilClass)
任何关于如何调试或在哪里找到问题的提示,我将不胜感激。
乔恩
@rmlockerd 和@ruby_object 在帮助调试方面都是正确的,但在一天结束时,我只是以一种不起作用的方式编写了这部分代码。
调试是关键
我正在开发“Advantage 数据库服务器”适配器扩展,以尝试与我有权访问(仍在使用中)的遗留数据库通信。
我已经更新了“Advantage”Gem,因此它适用于 Ruby 的 new/active 版本 https://github.com/t12nslookup/advantage and have seen that my copy of the activerecord-advantage-adapter https://github.com/t12nslookup/activerecord_advantage_adapter 适用于 ruby 1.9.3 和rails 3.2.22
我一直在尝试强制它与 rails 6 一起工作,并且通过一个简单的“ruby”脚本“需要”宝石并访问数据,但我无法在 rails 控制台获得相同的简单数据库查询。
我是 WSL 2 的 运行,如果它有什么不同的话(但我不相信。
ruby 2.7.0p0(2019-12-25 修订版 647ee6f091)[x86_64-linux]、Rails 6.0.3.3
我已将 rails6 分支添加到 activerecord-advantage-adapter github 项目。
Ruby 脚本:
jadams@Temp046317:~/code/ais-lims$ more ../testme.rb
require 'rubygems'
gem 'advantage'
gem "activerecord-advantage-adapter"
require "active_record"
ActiveRecord::Base.establish_connection(
adapter: 'advantage',
options: 'ServerType=Local|Remote; ReadOnly=True; CommType=TCP_IP; Compression=INTERNET',
database: '//172.27.176.1:6262/c$/ads/db/'
)
class Discount < ActiveRecord::Base
self.table_name = 'DISCOUNT'
self.sequence_name = :autogenerated
end
puts Discount.all.inspect
puts Discount.count
jadams@Temp046317:~/code/ais-lims$ ruby ../testme.rb
#<ActiveRecord::Relation [#<Discount >, #<Discount >, #<Discount >, #<Discount >]>
4
Rails 控制台:
jadams@Temp046317:~/code/ais-lims$ more config/database.yml
development:
adapter: 'advantage'
options: 'ServerType=Local|Remote; ReadOnly=True; CommType=TCP_IP; Compression=INTERNET'
database: '//172.27.176.1:6262/c$/ads/db/'
jadams@Temp046317:~/code/ais-lims$ more app/models/discount.rb
class Discount < ApplicationRecord
self.table_name = 'DISCOUNT'
self.sequence_name = :autogenerated
end
jadams@Temp046317:~/code/ais-lims$ rails c
Running via Spring preloader in process 728
Loading development environment (Rails 6.0.3.3)
2.7.0 :001 > puts Discount.all.inspect
Traceback (most recent call last):
1: from (irb):1
NoMethodError (undefined method `to_sym' for nil:NilClass)
2.7.0 :002 > puts Discount.count
Traceback (most recent call last):
2: from (irb):1
1: from (irb):2:in `rescue in irb_binding'
NoMethodError (undefined method `to_sym' for nil:NilClass)
任何关于如何调试或在哪里找到问题的提示,我将不胜感激。
乔恩
@rmlockerd 和@ruby_object 在帮助调试方面都是正确的,但在一天结束时,我只是以一种不起作用的方式编写了这部分代码。
调试是关键