I believe this was pulled from Rails 3 at the last minute because they decided they didn't need a state machine (Strongly disagree, especially considering it was a mixin), not much documentation exists, but it works very nicely.
Add this line to your bundle:
gem 'state_machine', :git => 'git://github.com/ivanvanderbyl/state_machine.git', :require => 'active_model/state_machine'
class TrafficLight < ActiveRecord::Base
include ActiveModel::StateMachine
state_machine do
state :red
state :green
state :yellow
event :change_color do
transitions :to => :red, :from => [:yellow], :on_transition => :catch_runners
transitions :to => :yellow, :from => [:green]
transitions :to => :green, :from => [:red]
end
end
def catch_runners
puts "That'll be $250."
end
end
light = TrafficLight.new
light.current_state #=> :red
light.change_color! #=> true
light.current_state #=> :green
light.change_color! #=> true
light.current_state #=> :yellow
light.change_color! #=> true
"That'll be $250."
EnvyLabs also wrote something about it back in the day http://blog.envylabs.com/2009/08/the-rails-state-machine/