I am trying to use aasm state machine
for going from one state
to another. But the issue
is that the statemachine
is moving through all states
without calling. Here is the code am using
include AASM
aasm column: 'state' do
state :pending, initial: true
state :checked_in
state :checked_out
event :check_in do
transitions from: :pending, to: :checked_in, guard: :verify_payment?
end
event :check_out do
transitions from: :checked_in, to: :checked_out
end
end
def verify_payment?
self.payment_status=="SUCCESS"
end
Here If I do Booking.create
it returns with checked_out
state even initially instead of the expected pending
Why its returning the last
expected state instead of initial
??