Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
state_machine 似乎是人们说要使用的那个,至少我和他们交谈过。它与环境无关,因此您不必在应用程序的某个部分使用一个状态机,而在应用程序的另一部分使用完全不同的状态机。
2015 年 2 月更新
遗憾的是,状态机已不再维护,并且存在许多问题,这使其成为不太受欢迎的选择。然而,该项目的这个分支得到了积极维护,并且看起来很稳定。
state_machine seems to be the one people say to use, at least who I've spoken to. It is environment agnostic, so you don't have to use one state machine in one part of your app, and a completely different one in another part of your app.
Update February 2015
State Machine is unfortunately no longer maintained and there are many issues, which makes it a less favourable choice. However, this fork of the project is actively maintained and appears to be stable.
我最终使用了 Stateflow 并且喜欢它。 https://github.com/ryanza/stateflow
它运行在rails 3.0上,方法类似状态机代码存在于多个 Rails 3.0 测试版中,但从最终版本中删除。我还没有继续了解当前关于在 Rails 中使用状态机的想法是什么 - 但我想如果状态机在未来的版本中重新集成,它会有点像这样。如果我想放弃 gem 并使用核心功能,希望这意味着最少的代码更改
I ended up using stateflow and like it. https://github.com/ryanza/stateflow
It runs with rails 3.0, and it is similar in approach to the state machine code that was in several of the rails 3.0 betas but dropped from the final release. I've not followed along to see what the current thinking about having a state machine inside rails is - but I guess that if a state machine gets reintegrated in a future release it will be a bit like this. Hopefully that will mean minimal code changes if I ever want to drop the gem and use core functionality
我会谨慎对待转变。作者/提取者说他没有时间维护它,并且通常在他的新项目中偏爱 state_machine 。
另一方面,它确实有效(尽管检查未解决的问题以查看它是否适用于您的情况)。我自己在一个项目中使用转换,但用于一个简单的状态机。
我之前在 Rails 2 项目中使用过 actions 作为状态机,而且效果非常好(即使是非常复杂的状态机)
I would approach Transitions with care. The author/extractor says he doesn't have time to maintain it, and usually favors state_machine on his new projects.
On the other hand, it does work (although check the open issues to see if it will work in your case). I'm using Transitions myself on a project, but for a trivial state machine.
I've used acts as state machine before, on a Rails 2 project, and it did really well (even with very complex state machines)
SimpleStateMachine 是一个简单的 DSL,用于使用状态转换防护来装饰现有方法。
它与 ActiveModel 验证一起使用,并允许使用参数调用事件:
它可以挽救异常:
SimpleStateMachine is a simple DSL to decorate existing methods with state transition guards.
It works with ActiveModel validations and allows events to be called with arguments:
It can rescue exception:
即使是最简单的状态机 gem 也有比我需要的更多的功能,所以我决定推出自己的解决方案。我尝试了 Transitions 和 Stateflow,但两者都存在一些小问题。
Even the simplest state machine gems had way more features than I needed, so I just decided to roll my own solution. I tried Transitions and Stateflow, but had minor issues with both.
我会推荐 Workflow 因为我觉得它是所有可用状态机中最简单的。
I would recommend Workflow as i feel its the easiest of all the state machines available .