Skip to content

Instantly share code, notes, and snippets.

@macfanatic
Created January 31, 2017 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macfanatic/fb53c0f8c49138b617fab34996efe184 to your computer and use it in GitHub Desktop.
Save macfanatic/fb53c0f8c49138b617fab34996efe184 to your computer and use it in GitHub Desktop.
# app/models/post.rb
class Post < ActiveRecord::Base
attr_accessible :body, :status, :title
validates :title, presence: true, uniqueness: true
validates :body, presence: true
DRAFT = 'draft'
REVIEWED = 'reviewed'
PUBLISHED = 'published'
state_machine :status, initial: DRAFT do
event :peer_review do
transition DRAFT => REVIEWED
end
event :publish do
transition REVIEWED => PUBLISHED
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment