如何在 Rails 中的 aasm 回调中访问旧状态和新状态?
我对 Ruby 和 Rails 都是新手。
我正在使用 AASM 将状态机行为放入模型类中。根据新旧状态,我想以不同的方式处理状态更改事件。
如何以“to”和“from”状态作为参数调用“after”回调,或者访问 AASM 持有的内部字段(如果这些字段有我需要的内容)? ...或者我只需要添加之前和之后的回调并将之前的状态保存在之前的回调中?
I am new to both Ruby and Rails.
I'm using AASM to put state machine behavior into a model class. Depending on the old and new states I want to handle the state change event in different ways.
How do I either invoke the "after" callback with the "to" and "from" states as arguments or access the internal fields of held by AASM if those have what I need? ...or do I just have to add both before and after callbacks and save the previous state in the before callback?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以访问 ModelClass.aasm_state()
如果您对不同的状态有不同的转换,
。 Aasm 有很好的文档记录。您可以在 aasm 的自述文件中找到说明:https://github.com/rubyist/aasm
You can access ModelClass.aasm_state()
If you have different transitions for different states.
Aasm is pretty well documented. You can find the instructions in the README for aasm: https://github.com/rubyist/aasm