Musician, Ruby on Rails Entusiast, Composer, Programmer and Lover of Hot Sauce

A Better State Machine

Posted: April 19th, 2010 | Author: mindtonic | Filed under: Design Patterns, Rails Plugins, Ruby On Rails | Tags: , , | No Comments »

I have been using AASM as my default State Machine Rails plugin for quite some time. It has always worked great, but now there is a better, more thorough State Machine I recommend. state_machine 0.9 has just been released, and as you can read in this blog post, they are rapidly moving towards the finalization of the 1.0 version. http://www.pluginaweek.org/2010/04/19/state_machine-0-9-0-locked-and-loaded!

What lead me to discover this fantastic plugin was the need to be able to call ActiveRecord observers in relation to the State of an object. With AASM, I had to incorporate my lib class calls in a method that was referenced in a state definition. I didn’t like this because it required my Model to have too much knowledge of the outside world. I think it is a best practice to encapsulate this type of functionality into an observer, leaving the model to be happy in it’s own little world. state_machine accomplishes this by allowing the placement of observer calls using a DSL provided by the plugin.



Leave a Reply