I am developing application in rails , where i have made use of state_machine (https://github.com/pluginaweek/state_machine/).
Here i wanted to check condition in one state , based on condition
state changes from another state . (i.e consider state1 , state2 and
state3 are states if(a>b) {state1 => state2 }else {state1 =>state3}) ,
i wanted to know how this will be accomplished in state machine .
kindly help me out in this
In state_machine, you define events that change the state of the underlying object. You can also set the state attribute to the state that you want.
In your case you’d do:
You can also check the state with:
What you should do is define an event that describes the transition from state1 to state2 or state3. For instance:
Then, you transition state like this:
Using the events are a lot cleaner way of manipulating the state. This is all covered in the Readme on the plugin’s github page