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

Ruby on rails 为什么我的gem导致活动记录无法加载?,ruby-on-rails,ruby,rubygems,gem,Ruby On Rails,Ruby,Rubygems,Gem,这是我的珍宝: 这就是我如何将其包含在我的GEM文件中的方式: gem "deep_cloning", :git => "git://github.com/DerNalia/deep_cloning.git" 以下错误所在的行是: ActiveRecord::Base.extend(DeepCloning) 链接到源文件: 。。。所以也许我扩展的ActiveRecord::Base错了 % bundle exec script/server -p3001 => Booting W

这是我的珍宝:

这就是我如何将其包含在我的GEM文件中的方式:

gem "deep_cloning", :git => "git://github.com/DerNalia/deep_cloning.git"
以下错误所在的行是:

ActiveRecord::Base.extend(DeepCloning)
链接到源文件:

。。。所以也许我扩展的
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

您可能应该在gem中尝试
要求使用“activerecord”


关于
扩展
包括

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"

您可能应该在gem中尝试
要求使用“activerecord”


关于
扩展
包括

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"

看起来您正试图在加载活动记录之前引用ActiveRecord::Base看起来您正试图在加载活动记录之前引用ActiveRecord::Base问题:我添加了“ActiveRecord”,并且我的任何对象都没有.clone!method=\也许您应该使用
ActiveRecord::Base.send:include,DeepCloning
extend
include
经常出错。如果我包括deepcloning,我不就可以将方法作为类变量而不是实例变量使用吗?目标是能够完成myARObject.clone!(params)=\n我想你的情况正好相反。哦,我看到你添加了示例,我必须尝试一下。但问题是:我添加了require'ActiveRecord',并且我的所有对象都没有.clone!method=\也许您应该使用
ActiveRecord::Base.send:include,DeepCloning
extend
include
经常出错。如果我包括deepcloning,我不就可以将方法作为类变量而不是实例变量使用吗?目标是能够完成myARObject.clone!(params)=\n我想你的情况正好相反。哦,我看到你添加了示例,我必须尝试一下。