我正在使用 Rail 4.2.3 和 aasm gem 4.1 版是否可以在一个模型中为枚举字段添加两个状态机?
我有枚举状态:[:active, :suspended, :deleted] 和枚举活动:[:working, :stopped]
我不会像这样的2个状态机:
aasm(:connection_state, column: :state, enum: true do
state :active, initial: true
state :suspended
state :deleted
event :activate do
transitions from: :suspended, to: :active
transitions from: :deleted, to: :active
end
event :suspend do
transitions from: :active, to: :suspended
end
event :mark_as_deleted do
transitions from: [:active, :suspended], to: :deleted
end
end
和其他状态机:
aasm(:activity_state, column: :activity, enum: true do
state :working, initial: true
state :stopped
event :start_working do
transitions from: :stopped, to: :working
end
event :stop_working do
transitions from: :working, to: :stopped
end
end
但规格因错误而失败:
expect(subject).to transition_from(:active).to(:suspended).on_event(:suspend)
AASM::UnknownStateMachineError:在 ModelName 中没有定义名称为“默认”的状态机
我错过了什么?