How to set up state security in AASM

Is there a way to define a guard (e.g. has_legs? ) That is checked before entering a state (e.g. running ) anyway?

The list of all possible callbacks has protection for events and transitions, but not for events.

I tried to do a conditional check for the model. It worked when the event was executed, but not for aasm methods (e.g. may_run? ).

+7
ruby-on-rails aasm
source share
1 answer

I do not know how to build a method. I would use a workaround with a hash containing default options.

 DEFAULT_EVENT_OPTS = { guard: ... } DEFAULT_TRANSITION_OPTS = { ... } event :clean, DEFAULT_EVENT_OPTS.merge({ ... }) do transitions DEFAULT_TRANSITION_OPTS.merge({:from => :running, :to => :cleaning, :guard => :cleaning_needed?}) end 
0
source share

All Articles