【发布时间】:2011-08-25 17:39:15
【问题描述】:
只是希望有人可以为我解释一下..
我有一个导入模块的站点类:
网站
class Site < ActiveRecord::Base
include TrackableChanges
...
在 trackable_changes.rb 中
我有这个代码..
module TrackableChanges
include ActiveSupport::Callbacks
def self.included(base)
# Initialize module.
base.has_many :change_requests, :as => :model, :dependent => :destroy
#Callbacks
base.before_save :before_save_change_request
base.after_save :after_save_change_request
base.before_destroy :before_destroy_change_request
Facility
end
...
对Facility的引用真的让我很困惑(我在这里放了一个微不足道的引用......)。基本上在 Facility.rb 我有这个..
class Facility < ActiveRecord::Base
acts_as_citier
acts_as_citier 看起来有点像这样:
module Citier
def self.included(base)
# When a class includes a module the module’s self.included method will be invoked.
base.send :extend, ClassMethods
end
end
ActiveRecord::Base.send :include, Citier
现在.. 只需在我的初始模块中引用 Facility,它就会转到acts_as_citier gem 并扩展我的 Site 类的 ActiveRecord。我想要为我的设施使用acts_as_citier gem,但不是为我的站点使用。
任何人都可以帮助阻止这种包括引入这个不需要的参考的线索!?
编辑
如果没有它通过引用 gem act_as_citier 引入在 Facility 中定义的 ActiveRecord 类添加,我似乎根本无法引用该类 Facility
城市这样做...
ActiveRecord::Base.send :include, Citier
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3