AASM: Transitions from any state?
Asked Answered
L

2

33

I am using AASM. Is it possible to transition from any state? For example:

aasm_event :publish do
  transitions :to => :publish, :from => ANY_STATE
end

I know that it is possible to pass an array of states to :from, but this isn't what I'm after. I have tried omitting the :from completely, but that didn't work.

Liddell answered 6/2, 2011 at 9:57 Comment(0)
R
84

aasm now supports transitions without any from specified, which will allow transitioning from any state.

aasm_event :publish do
  transitions to: :publish # from ANY
end

(bragging rights: I added this feature because I needed it)

Roop answered 19/10, 2012 at 6:43 Comment(1)
Thanks for adding the feature to the codebase. All AASM releases >= 3.0.10 include this now.Aflcio
I
6

You can get the states via the aasm_states class method, provided they have already been defined earlier in the code.

aasm_event :publish do
  transitions :to => :publish, :from => aasm_states.map(&:name)
end
Institutor answered 6/2, 2011 at 12:12 Comment(1)
Thx for the answer but feels hack-ish. AASM should support :all or :any.Tocci

© 2022 - 2024 — McMap. All rights reserved.