当在父模型中定义 AASM 时,有没有办法在子模型中添加回调?
class Parent
include AASM
aasm do
state :initialised, :initial => true
state :filled_out
state :authorised
event :fill_out do
transitions :from => :initialised, :to => :filled_out
end
event :authorise, :before => :stamp_it do
transitions :from => :filled_out, :to => :authorised
end
def stamp_it
puts "Stamped"
end
end
end
在子类中,我们要添加回调mail_it
。看来我们必须event
从父级重新定义整个以添加另一个回调?
class Child < Parent
aasm do
event :authorise, :before => [:stamp_it, :mail_it] do
transitions :from => :filled_out, :to => :authorised
end
end
def mail_it
puts "Mail it"
end
end