Reputation: 1038
I am developing state machine using state_machine on rails, here i have different states which is defined , based on conditions state will change to another state . Here my question is how to get the previous state? and my second question is how to list all the states in state machine ?
i will explain my question with example say i have 3 states say state1,state2,state3 initially it will be in state1. when event1 is executed state changes from state1=>state2 , now i wanted to know which is my previous state. kindly help me out in figuring out this.
Upvotes: 4
Views: 2218
Reputation: 12412
I used paper_trail gem and reified previous versions.
This allows me to follow up the sequence of states that the object went through.
With paper_trail you can even retrieve the Originator or Terminator of that state change.
Upvotes: 1
Reputation: 26
This may be what you're looking for: https://github.com/wvanbergen/state_machine-audit_trail
Upvotes: 1
Reputation: 593
if you are looking for the list of previous states from an object, i'm afraid u can not. state_machine only changes a column value in your models database register, dosen't stores any type of history.
Please check solutions like acts_as_versioned (https://github.com/technoweenie/acts_as_versioned) to store and play with your models versions.
Also you want to check aasm gem https://github.com/rubyist/aasm
Cheers
Upvotes: 1