引擎使用Mongoid - Mongoid没有正确加载?

时间:2013-02-19 09:50:56

标签: ruby-on-rails ruby mongoid

我正在做一个rails引擎,我在其中设置了几个ruby模块,这些模块将包含在客户端Rails应用程序的模型中。 我面临一个奇怪的问题:我的引擎内的模块大量使用mongoid。 (将字段附加到模型,声明索引和东西)但是当我对某些字段使用DateTime类型时,它会在保存时抛出NoMethod错误,如: XXXX的未定义方法` bson_dump '

我检查了Mongoid的来源并确定了所有扩展逻辑(尤其是DateTime)的实现位置。 是不是我没有正确地要求依赖或什么?

感谢您的关注

我的模块之一如下:

module Engine::Event

   included do
      include Mongoid::Document
      field :starts_at, :type => DateTime
   end

end

# In my client application
class MyEvent
   include Engine::Event
end

MyEvent.new :starts_at => DateTime.now

以下是错误的堆栈跟踪的一部分:

NoMethodError: undefined method `__bson_dump__' for Wed, 20 Feb 2013 09:47:58 +0000:DateTime
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/bson/extensions/hash.rb:36:in `block in __bson_dump__'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/bson/extensions/hash.rb:35:in `each'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/bson/extensions/hash.rb:35:in `__bson_dump__'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/bson/document.rb:11:in `serialize'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/protocol/message.rb:129:in `block in serialize_documents'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/protocol/message.rb:128:in `each'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/protocol/message.rb:128:in `serialize_documents'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/protocol/message.rb:287:in `serialize'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/connection.rb:153:in `block in write'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/connection.rb:151:in `each'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/connection.rb:151:in `write'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:560:in `block (2 levels) in flush'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:129:in `ensure_connected'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:559:in `block in flush'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:574:in `logging'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:558:in `flush'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:547:in `process'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:259:in `insert'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/session/context.rb:63:in `block in insert'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/session/context.rb:109:in `block in with_node'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/cluster.rb:205:in `block in with_primary'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/node.rb:189:in `ensure_primary'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/cluster.rb:204:in `with_primary'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/session/context.rb:108:in `with_node'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/session/context.rb:56:in `insert'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/collection.rb:91:in `block in insert'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/session.rb:312:in `with'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/moped-1.3.2/lib/moped/collection.rb:90:in `insert'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.20/lib/mongoid/persistence/operations/insert.rb:27:in `block in persist'
/Users/codi/.rvm/gems/ruby-1.9.3-p327/gems/mongoid-3.0.20/lib/mongoid/persistence/insertion.rb:25:in `block (2 levels)

如果Mongoid被正确加载,那不应该发生......:S

0 个答案:

没有答案