我们在很多模型中都使用了 AASM,但我们正在考虑对模型进行一些简化。我们想做的一件事是将所有通知内容从模型中移到观察者中。
所以考虑:
class ClarificationRequest < ActiveRecord::Base
include AASM
aasm_initial_state :open
# States
aasm_state :open
aasm_state :closed
# Events
aasm_event :close, :after => :notify_closed do transitions :to => :closed, :from => [:open,:replied], :guard => :can_close? end
end
我试过这个,但没有运气:
class ClarificationRequestObserver < ActiveRecord::Observer
observe :clarification_request
def after_close
puts '############### message from observer!!!!!'
end
end
如何将 :notify_closed 移动到观察者?
谢谢!
.卡里姆