开发者

Extending Mongoid with class and instance methods from Gem

in ActiveRecord, I'm used to do this:

ActiveRecord::Base.send :include, MyGem::ActsAsMagnific::Base

And it works like a charm.

But I can't achieve the same result in Mongoid. I tried this without success:

Mongoid::Document::ClassMethods.开发者_运维技巧class_eval do
  include MyGem::ActsAsMagnific::Base
end

I'm using rails3 and I've to include class and instance methods.


If you want to add class methods to Mongoid::Document, maybe you should try to extend it. In any case, it's preferable to use ActiveSupport::Concern for task like this. For example see this post: Using ActiveSupport::Concert


I can't comment on the answer above, but the new URL that replaces the one that Roman stated is: http://pivotallabs.com/using-activesupport-concern-for-easy-mix-ins/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜