获取 state_machine Rails 中先前的状态
我正在 Rails 上使用 state_machine 开发状态机,这里我定义了不同的状态,根据条件状态将更改为另一个状态。这里我的问题是如何获得之前的状态?我的第二个问题是如何列出状态机中的所有状态?
我会用例子解释我的问题,说我有 3 个州说 state1,state2,state3 最初将处于 state1。当事件1是 执行状态从 state1=>state2 更改,现在我想知道 这是我之前的状态。请帮我解决这个问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能就是您正在寻找的内容:https://github.com/wvanbergen/state_machine-audit_trail
This may be what you're looking for: https://github.com/wvanbergen/state_machine-audit_trail
如果您正在寻找某个对象的先前状态列表,恐怕您不能。
state_machine 仅更改模型数据库寄存器中的列值,不存储任何类型的历史记录。
请检查acts_as_versioned (https://github.com/technoweenie/acts_as_versioned) 等解决方案来存储和使用您的模型版本。
您还想检查 aasm gem https://github.com/rubyist/aasm
干杯
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
我使用 paper_trail gem
并具体化了以前的版本。
这使我能够跟踪该对象经历的状态顺序。
使用 paper_trail,您甚至可以检索该状态更改的发起者或终结者。
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.