Skip to content

Specifying a Human Display Name

CodeMeister edited this page Feb 28, 2023 · 1 revision

states with a human display name:

The value used for a state is frequently a shortened, more succinct, version of the status displayed to a user. The human_name option attaches a String phrase for an individual state. By default, each state's human name will be its titleized symbol name.

example:

class Post < ActiveRecord::Base
  include StateGate

  state_gate :status do
    state :draft
    state :pending, human: 'Pending Approval'
    state :published
    state :archived

    default :published
  end
end

Post.human_statuses #=> ['Draft', 'Pending Activation', 'Published', 'Archived']

Clone this wiki locally