在state_machine中,如何找到当前状态下哪些事件是有效的?

发布于 2024-11-26 05:13:15 字数 298 浏览 3 评论 0原文

我在我的 Rails3 应用程序中使用 Aaron Pfeifer 的 state_machine gem - 它很漂亮。

如何获取当前状态下合法的事件列表?我的意思是不是的意思是my_model.state_path.events它返回所有可从当前状态传递的事件——我只想要那些在当前状态下可用。

我很确定我只是忽略了一些显而易见的事情。

I am using Aaron Pfeifer's state_machine gem in my Rails3 app -- it's nifty.

How do get a list of events are legal in the current state? By this, I do not mean my_model.state_path.events which returns all events transitively traceable from the current state -- I want only those that are available in the current state.

I'm pretty sure I'm simply overlooking something obvious.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-12-03 05:13:15

Aaron 本人在 PluginAWeek:Core 组邮件列表上回答了这个问题:

嗨 - 您可以看到为以下内容生成的帮助器方法列表
文档中 #state_machine 宏的每个状态机
标题“实例方法”:
http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine...
在这里您会注意到一些可以帮助您的实例方法:

  • state_events - 获取可以在
    当前对象的状态(使用非限定事件名称)
  • state_transitions - 获取可以进行的转换列表
    当前对象的状态
  • state_paths - 获取可以进行的转换序列列表
    从当前对象的状态运行希望这有帮助!最好,亚伦

Aaron himself answered the question on the PluginAWeek:Core group mailing list:

Hi - You can see the list of helper methods that get generated for
each state machine in the docs for the #state_machine macro under the
heading "Instance Methods":
http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine...
Here you'll notice a few instance methods which should help you along:

  • state_events - Gets the list of events that can be fired on the
    current object’s state (uses the unqualified event names)
  • state_transitions - Gets the list of transitions that can be made on
    the current object’s state
  • state_paths - Gets the list of sequences of transitions that can be
    run from the current object’s state Hope this helps! Best, Aaron
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文