Reputation: 115541
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.
Upvotes: 1
Views: 1092
Reputation: 6052
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/
Upvotes: 0
Reputation: 13058
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
Upvotes: 1