4
全部 我想在ActiveRecord對象上實現狀態機https://github.com/pluginaweek/state_machine gem。但我想嵌套state_machines。到目前爲止,我有這個簡單的狀態機:ruby類與嵌套狀態機使用state_machine寶石
class Document < ActiveRecord::Base
state_machine :initial => :new do
before_transition :new => :processing, :do => :start_processing
event :start_processing do
transition :new => :upload_to
end
event :finish_processing do
transition :processing => :ok
end
event :error_in_processing do
transition :processing => :error
end
event :to_trash do
transition :processing => :trash
end
end
但我想做些什麼,是有嵌套狀態機這將過渡到處理狀態後開始。這個嵌套狀態機將具有諸如uploading_to_xxx,extracted_from_yyy,pending,verifying等狀態。 我大概可以用一個狀態機實現這一點,但我更願意使用嵌套狀態機。我在網上找不到任何樣本。 state_machine是否支持這個用例?或者如果有其他的寶石,你能指出我嗎? 感謝
IIRC(我可能沒有),這是不支持開箱即用的做到這一點。 –