Search code examples
ruby-on-railsrubystates

List ALL states within States Machine


How can I get an array of all possible states from my CardHolderStateMachine?

So far I only have two (:pending and :active) but I want to grab them to use in a dropdown.

class CardHolderStateMachine
  include Statesman::Machine

  state :pending, initial: true
  state :active

  transition from: :pending, to: [:active]

By "states" I don't mean States of America (just to avoid confusion as there are a few posts about that which have nothing to do with Statesman)


Solution

  • Have you tried CardHolderStateMachine.states?

     > CardHolderStateMachine.states
    => ["pending", "active"]
    

    It always pays off to check the source code.