Calling a method on state change with AASM
-
05-07-2019 - |
Question
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
Solution
Nevermind - figured it out:
aasm_state :paid, :enter => :update_foo
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow