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.

lucapette
  • 20,564
  • 6
  • 65
  • 59
gjb
  • 6,237
  • 7
  • 43
  • 71

2 Answers2

82

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)

swrobel
  • 4,053
  • 2
  • 33
  • 42
  • 6
    Thanks for adding the feature to the codebase. All AASM releases >= 3.0.10 include this now. – alto Oct 21 '12 at 07:10
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
vise
  • 12,713
  • 11
  • 52
  • 64