activemdb基类不能继承?

时间:2012-09-17 10:13:40

标签: mysql ruby-on-rails ms-access

我试图通过activemdb gem访问Rails中的mdb文件。我得到的问题是,当我尝试访问或使用此gem时,它会产生以下错误

NameError: uninitialized constant ActiveMDB
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:469:in `load_missing_constant'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing'
from /home/confiz/Project/redmine/LMS/redmine-1.4/app/models/beacon.rb:2
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:406:in `load_without_new_constant_marking'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:406:in `load_file'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:405:in `load_file'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:285:in `require_or_load_without_engine_additions'
from /home/confiz/Project/redmine/LMS/redmine-1.4/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb:132:in `require_or_load'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:451:in `load_missing_constant'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing'
from /home/confiz/.rvm/gems/ruby-1.8.7-p358@lms/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing'
from (irb):1

这是我的宝石列表

*** LOCAL GEMS ***

actionmailer (2.3.14)
actionpack (2.3.14)
activemdb (0.2.2)
activerecord (2.3.14)
activeresource (2.3.14)
activesupport (2.3.14)
bundler (1.1.3)
coderay (1.0.7)
edavis10-object_daddy (0.4.3)
fastercsv (1.5.5)
hoe (3.0.8)
i18n (0.4.2)
json (1.7.5)
metaclass (0.0.1)
mocha (0.12.3)
mysql (2.8.1)
net-ldap (0.3.1)
rack (1.1.3)
rails (2.3.14)
rake (0.9.2.2)
rdoc (3.12)
rmagick (2.13.1)
ruby-openid (2.1.8)
rubygems-bundler (0.2.8)
rvm (1.11.3.3)
shoulda (2.10.3)
sqlite3 (1.3.6)
tzinfo (0.3.33)

这里是我访问activemdb的代码

  

class Beacon < ActiveMDB::Base
    set_mdb_file 'att2000.mdb'
end

1 个答案:

答案 0 :(得分:2)

这是因为出于某种原因,当gem本身被称为“activemdb”时,gem中的文件是“active_mdb.rb”。这可以防止rails自动require

尝试将其添加到您的Gem文件中:

gem 'activemdb', :require => 'active_mdb'

然后它应该工作。