In state_machine, how do I find which events are valid from the current state?

烂漫一生 提交于 2019-12-24 09:57:57

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/6783292/in-state-machine-how-do-i-find-which-events-are-valid-from-the-current-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!