10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/commontator/acts_as_commontable.rb', line 10
def acts_as_commontable(options = {})
class_eval do
has_one :thread, :as => :commontable, :class_name => 'Commontator::Thread'
has_many :comments, :class_name => 'Commontator::Comment', :through => :thread
has_many :subscriptions, :class_name => 'Commontator::Subscription', :through => :thread
after_initialize :create_thread, :unless => :thread, :if => :id
before_validation :build_thread, :unless => :thread
validates_presence_of :thread
cattr_accessor :commontable_config
self.commontable_config = Commontator::CommontableConfig.new
self.is_commontable = true
def create_thread
thread = Commontator::Thread.new
thread.commontable = self
thread.save!
self.reload
end
end
end
|