我想包括一個模塊,只有當條件得到滿足。Rails包含模塊上的條件
module PremiumServer
def is_premium
true
end
end
class Server
include Mongoid::Document
include PremiumServer if self.premium
field :premium, :type => Boolean, :default => false
end
這是行不通的,我不明白爲什麼。有人可以告訴我,我應該如何根據遇到的情況包含模塊,如上所述?
謝謝!
編輯:
我找到了答案,我的問題就在這裏:Mongoid and carrierwave
不過,我授予問題上的答案,因爲它可能是更有效的方法。
是溢價實例方法或字段?如果是這樣,那麼這將不起作用,因爲包含在加載時發生在課堂級別。 – 2011-06-04 11:29:45