作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有两个事件:
event :event1, after: :event2! do
transitions to: :state2, from: :state1, guard: proc {some func}
transitions to: :state3, from: :state1
end
event :event2 do
transitions to: :state3, from: state2, guard: proc {some func}
end
如何仅在 event1 中设置第一次转换后的回调? (我无法将第二次转换替换为其他事件)
我试过了
event :event1 do
transitions to: :state2, from: :state1, after: :event2!, guard: proc {some func}
transitions to: :state3, from: :state1
end
但是没有效果
最佳答案
我不确定我是否准确地理解了你。你只想在这个转换之后运行 event2
:transitions to: :state2, from: :state1, guard: proc {some func}
,对吧?
event :event1 do
transitions to: :state2, from: :state1, :after => Proc.new {|*args| set_process(*args) } , guard: proc {some func}
transitions to: :state3, from: :state1
end
def set_process(name)
event2!
end
或者试试这个。
event :event1 do
transitions to: :state2, from: :state1, guard: proc {some func}
transitions to: :state3, from: :state1
after do
event2! if self.state2?
end
end
event :event2 do
transitions to: :state3, from: state2, guard: proc {some func}
end
这段代码意味着,当 guard 返回 true 时,它将进行第一次转换,否则进行第二次转换。转换后,如果它是 state2,它将进行 event2。您可以在 aasm 找到更多详细信息。 .
In the event of having multiple transitions for an event, the first transition that successfully completes will stop other transitions in the same event from being processed.
您可以在回调中编写任何代码,就像 rails 回调一样。
关于ruby-on-rails - 如何仅在 aasm 中为特定转换设置回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31437512/
我是一名优秀的程序员,十分优秀!