views:

643

answers:

1

How do I go about calling a method on state change in AASM?

I'd like to call update_foo when the state transitions to paid in the following model:

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
+2  A: 

Nevermind - figured it out:

aasm_state :paid, :enter => :update_foo
Mr. Matt