使用AASM调用状态更改方法

时间:2008-10-30 15:47:21

标签: ruby-on-rails ruby state-machine

如何在AASM中调用状态更改方法?

当状态转换为以下模型中的付费时,我想调用update_foo:

class Foo < ActiveRecord::Base
  include AASM

  # State Machine
  aasm_initial_state :incomplete
  aasm_state :incomplete
  aasm_state :paid

  aasm_event :pay do
    transitions :from => :incomplete, :to => :paid
  end

  def update_foo
  ...
  end
end

1 个答案:

答案 0 :(得分:4)

没关系 - 想通了:

aasm_state :paid, :enter => :update_foo