Skip to content

Instantly share code, notes, and snippets.

@DBA
Created June 3, 2010 01:50
Show Gist options
  • Save DBA/423315 to your computer and use it in GitHub Desktop.
Save DBA/423315 to your computer and use it in GitHub Desktop.
require 'active_record/transitions.rb'
class Forum < ActiveRecord::Base
include ActiveRecord::Transitions
acts_as_nested_set
# Associations
has_many :posts
# Validations
validates_presence_of :name, :state
state_machine do
state :open
state :locked
state :hidden
event :open do
transitions :to => :open, :from => [:locked, :hidden]
end
event :lock do
transitions :to => :locked, :from => [:open, :hidden]
end
event :hidden do
transitions :to => :hidden, :from => [:open, :locked]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment