Search code examples
ruby-on-railsrubyaasm

What is the best way to halt a transition with AASM


When a method being called in the success or enter phases of a state transition throw errors, what is the best way to catch this and ensure that the state reverts back to the previous state.

I'm using the AASM gem.


Solution

  • What about using the :guard option to make sure the transition can be performed? If the guard method returns false, the transition isn't executed at all. So, I'd check if every condition of the transition is met with the guard method, first.