[英]state_machine vs aasm gems for app ruby on rails 3.2
I need a state machine for a message private system and order status system. 我需要一个状态机用于消息专用系统和订单状态系统。
you can see these two gems: 你可以看到这两个宝石:
https://github.com/pluginaweek/state_machine https://github.com/pluginaweek/state_machine
https://github.com/rubyist/aasm https://github.com/rubyist/aasm
I'm using mongoid with mongodb database 我正在使用mongoid和mongodb数据库
What gem is most appropriate for this features? 什么宝石最适合这个功能?
Update: 更新:
Check out the recent RailsCast: A Tour of State Machines 查看最近的RailsCast: 状态机之旅
Previous Answer: 上一个答案:
Both gems are working great, are compatible with Mongoid, and are actively maintained. 这两个宝石都很好用,与Mongoid兼容,并且都是积极维护的。
I've used AASM in the past, and it has been around a bit longer, but the state_machine gem has quite a bit more functionality and more options. 我过去曾经使用过AASM,它已经存在了一段时间,但是state_machine gem有更多的功能和更多的选择。 eg check the methods generated by state_machine on the base class (below their example); 例如,检查state_machine在基类上生成的方法(在它们的例子下面); you can define more details, eg transition callbacks, conditional transitions; 您可以定义更多细节,例如转换回调,条件转换; you can do path analysis, there's even a GraphViz generator to generate a nice picture of your state graph. 你可以进行路径分析,甚至还有一个GraphViz生成器可以生成状态图的漂亮图片。
If you need just a simple state machine, you can go with AASM. 如果您只需要一台简单的状态机,就可以使用AASM。 If you need to model more details like conditional transitions or transition callbacks, path analysis, do queries about the states a lot, or need nested state machines, then go for the state_machine gem. 如果您需要建模更多细节,如条件转换或转换回调,路径分析,对状态进行大量查询,或需要嵌套状态机,那么请转到state_machine gem。
References: 参考文献:
AASM : https://github.com/aasm/aasm AASM: https : //github.com/aasm/aasm
state_machine : https://github.com/pluginaweek/state_machine state_machine: https : //github.com/pluginaweek/state_machine
Additional info about state_machine: 有关state_machine的其他信息:
http://www.pluginaweek.org/2009/03/08/state_machine-one-machine-to-rule-them-all/ http://www.pluginaweek.org/2009/03/08/state_machine-one-machine-to-rule-them-all/
http://rdoc.info:8080/github/pluginaweek/state_machine/master/StateMachine/Machine http://rdoc.info:8080/github/pluginaweek/state_machine/master/StateMachine/Machine
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.