[英]Rails and the state_machine gem. Using callbacks in namespaced state machines to trigger events in in other machines
[英]ruby class with nested state machines using state_machine gem
我试图在ActiveRecord对象https://github.com/pluginaweek/state_machine gem上实现状态机。 但我想嵌套state_machines。 到目前为止,我有这个简单的状态机:
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
但我想做的是拥有嵌套状态机,它将在转换到处理状态后启动。 这个嵌套状态机将具有诸如uploaded_to_xxx,extracted_from_yyy,pending,验证等状态。 我可能只使用一个状态机来实现它,但我更喜欢使用嵌套状态机。 我在网上找不到任何样品。 state_machine是否支持此用例? 或者,如果还有其他宝石,你可以指点我吗? 谢谢
我想你可以通过工作流gem https://github.com/geekq/workflow来完成这个任务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.