Closed firedev closed 2 years ago
In the end I just did it like this, but I wish it was structured differently so event checked state and then executed the corresponding transition:
class Day
module WorkflowStates
extend ActiveSupport::Concern
included do
NEXT_STATE = {
'working' => 'not_working!',
'not_working' => 'vacation!',
'vacation' => 'sick!',
'sick' => 'working!'
}
include ::Workflow
workflow do
state :working do
event :not_working, transition_to: :not_working
end
state :not_working do
event :vacation, transition_to: :vacation
end
state :vacation do
event :sick, transition_to: :sick
end
state :sick do
event :working, transition_to: :working
end
end
end
def next_state
persisted? ? send(NEXT_STATE[workflow_state]) : save!
end
end
end
@firedev Thanks for the example. It worked great for me.
Here is what I have:
I just wanted to do
next_state!
all the time. But it causes these errors:How do I do circular states?
Thanks.