1

I'm currently using the aasm gem and it works great. Is it possible to define state just once instead of twice like below?

enum state: [:pending, :active, :inactive]

aasm column: :state, enum: true do
  state :pending, :active, :inactive
  
  event :accept do
    transitions from: :pending, to: :active
  end
  event :pause do
    transitions from: :active, to: :inactive
  end
  event :resume do
    transitions from: :inactive, to: :active
  end
end
vince
  • 2,374
  • 4
  • 23
  • 39
  • which version of the gem and of ActiveRecord are you using? – Tamer Shlash Oct 02 '20 at 22:31
  • aasm version 5.1.1 with ActiveRecord 6.0.3.3 – vince Oct 02 '20 at 22:39
  • 1
    Short answer is no, at least not using ``enum`` values. The gem only defines states for a state machine from its ``state`` directive(s). AASM just maps whatever states you define to the keys in the ``enum``; there's no logic in the code to create states automatically from enum keys. If you don't mind string states in the database, you can skip the ``enum`` and AASM will just use the state names as the database values. – rmlockerd Oct 03 '20 at 02:21

0 Answers0