Skip to content

Instantly share code, notes, and snippets.

@kubicek
Created December 23, 2008 23:47
Show Gist options
  • Save kubicek/39519 to your computer and use it in GitHub Desktop.
Save kubicek/39519 to your computer and use it in GitHub Desktop.
class Article < ActiveRecord::Base
acts_as_state_machine :initial => :opened
state :opened
state :state2, :enter => Proc.new {|model| puts "entering state 2" }, :after => Proc.new {|model| model.close! }
state :state3, :enter => Proc.new {|model| puts "entering state 3" }, :after => Proc.new {|model| model.close! }
state :state4, :enter => Proc.new {|model| puts "entering state 4" }
state :closed
state :returned
event :close do
transitions :to => :state2, :from => :opened
transitions :to => :state3, :from => :state2
transitions :to => :state4, :from => :state3
transitions :to => :closed, :from => :state4
end
event :return do
transitions :to => :returned, :from => :closed
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment