我正在尝试使用aasm state machine
从state
转到另一个issue
。但statemachine
是states
在没有通话的情况下正在通过所有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
。这是使用
Booking.create
此处如果我checked_out
,它会返回pending
状态,即使最初也不是预期的last
为什么它返回initial
预期状态而不是{{1}} ??
答案 0 :(得分:0)
问题原因是我有两个database fields
名为check_in
和check_out
。因此activerecord
会将其视为属性方法并在创建时触发这些事件。因此,此处的修复方法是将event
名称更改为与数据库中的名称不同的名称
include AASM
aasm column: 'state' do
state :pending, initial: true
state :checked_in
state :checked_out
event :move_to_check_in do
transitions from: :pending, to: :checked_in, guard: :verify_payment?
end
event :move_to_check_out do
transitions from: :checked_in, to: :checked_out
end
end
def verify_payment?
self.payment_status=="SUCCESS"
end