为什么我的gem导致活动记录无法加载?

时间:2012-02-06 16:06:27

标签: ruby-on-rails ruby rubygems gem

这是我的宝石:https://github.com/DerNalia/deep_cloning

这就是我在gemfile中包含它的方式:

gem "deep_cloning", :git => "git://github.com/DerNalia/deep_cloning.git"

以下错误所在的行是:

ActiveRecord::Base.extend(DeepCloning)

指向源文件的链接:https://github.com/DerNalia/deep_cloning/blob/master/lib/deep_cloning.rb

......所以..也许我正在延长ActiveRecord::Base错误?

% bundle exec script/server -p3001
=> Booting WEBrick
=> Rails 2.3.8 application starting on http://0.0.0.0:3001
/Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant ActiveRecord (NameError)
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `rake_original_const_missing'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/bundler/gems/deep_cloning-4d4df89848a4/lib/deep_cloning.rb:102
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `require'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from /Users/me/Work/GravityLabs/myproject/config/environment.rb:68
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/rails-2.3.8/lib/initializer.rb:111:in `run'
    from /Users/me/Work/GravityLabs/myproject/config/environment.rb:16
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
    from /Users/me/Work/GravityLabs/myproject/config.ru:3
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/rack-1.1.3/lib/rack/builder.rb:46:in `instance_eval'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/rack-1.1.3/lib/rack/builder.rb:46:in `initialize'
    from /Users/me/Work/GravityLabs/myproject/config.ru:1:in `new'
    from /Users/me/Work/GravityLabs/myproject/config.ru:1
    from script/server:3:in `eval'
    from /Users/me/.rvm/gems/ruby-1.8.7-p352@myproject/gems/rails-2.3.8/lib/commands/server.rb:78
    from script/server:3:in `require'
    from script/server:3

1 个答案:

答案 0 :(得分:1)

您应该在宝石中尝试require 'activerecord'


关于extendinclude

module M
  def a
    "hello"
  end
end

MyClass1.extend M
MyClass1.a #=> "hello"
MyClass.new.a #=> NoMethodError

MyClass2.send :include, M
MyClass2.a #=> NoMethodError
MyClass2.new.a #=> "hello"