我正在使用AASM来管理状态,只是希望有一些列来跟踪状态更改的时间,但是回调似乎不起作用。当然,问题可能出在我的方法上,我只是不确定。
aasm_state :active, :after => :activate
aasm_state :inactive
aasm_state :deactivated, :after => :deactivate
aasm_event :active do
transitions :to => :active, :from => [:inactive]
transitions :to => :active, :from => [:deactivated]
end
aasm_event :deactivated do
transitions :to => :deactivated, :from => [:active]
end
def activate
activated_at = Time.now
end
def deactivate
deactivated_at = Time.now
end发布于 2011-05-14 13:21:28
当使用aasm时,你不仅仅是在你的模型上调用你的激活/停用函数。
你还需要保存模型,所以当你做object.activate的时候,在那之后还要做object.save (至少在我使用的上一个版本中是这样的)
过渡看起来写得很好,所以我不认为这是问题所在
发布于 2011-08-24 15:54:05
在AASM的Rails3版本中,您需要将回调应用于转换事件,而不是状态。所以你的代码可以是-
aasm_state :active
aasm_event :active, :after => :activate do
transitions :to => :active, :from => [:inactive]
transitions :to => :active, :from => [:deactivated]
endhttps://stackoverflow.com/questions/5998528
复制相似问题