简体   繁体   中英

Getting previous states in state_machine rails

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.

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.

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

这可能是您正在寻找的: https//github.com/wvanbergen/state_machine-audit_trail

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM