Skip to content

Creating a StateGate

CodeMeister edited this page Feb 28, 2023 · 10 revisions

This example creates a minimal state-gate on the :status attribute of the Post class, allowing any state to transition to any other state without restriction.

class Post < ActiveRecord::Base
  include StateGate

  state_gate :status do
    state :draft
    state :pending
    state :published
    state :archived
  end
end

Post.new.status  #=> 'draft'

Clone this wiki locally