I use state machine gem called AASM on rails.
There are an event which has two types of transitions.
Three three types of state
state pending
state past_due
state paid
pending
can be changed into paid
past_due
can be changed into paid
event :pay do
transitions from: [:pending, :past_due], to: :paid
end
So here I'd love to do some action only if past_due
goes paid
.
Any idea?
One way to do this is to define transitions in two separate statements:
event :pay do
transitions from: :pending, to: :paid
transitions from: :past_due, to: :paid, after: :do_your_custom_action
end
See more about callbacks in the docs.