Codebeef
Codebeef

Reputation: 44006

Calling a method on state change with AASM

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

Upvotes: 1

Views: 2691

Answers (1)

Codebeef
Codebeef

Reputation: 44006

Nevermind - figured it out:

aasm_state :paid, :enter => :update_foo

Upvotes: 6

Related Questions