state_machine vs aasm gems for app ruby on rails 3.2
Asked Answered
T

1

10

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/rubyist/aasm

Edited..

I'm using mongoid with mongodb database

What gem is most appropriate for this features?

Tropism answered 28/9, 2012 at 11:56 Comment(1)
Either is perfectly appropriate, they are both state machine gems that work well with activerecord, are actively maintained and used heavily. I don't think you can go wrong with either of these. I have used both but generally prefer the syntax of the pluginaweek state machine gem a bit better.Keverne
G
15

Update:

Check out the recent RailsCast: A Tour of State Machines

One thing to mention is that when you use a state machine, it may make it difficult to generate objects for tests which are in an invalid state..

Previous Answer:

Both gems are working great, are compatible with Mongoid, and are actively maintained.

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. e.g. check the methods generated by state_machine on the base class (below their example); you can define more details, e.g. transition callbacks, conditional transitions; you can do path analysis, there's even a GraphViz generator to generate a nice picture of your state graph.

If you need just a simple state machine, you can go with 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.

References:

AASM : https://github.com/aasm/aasm

state_machine : https://github.com/pluginaweek/state_machine

Additional info about state_machine:

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

Goldia answered 2/10, 2012 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.