0

我正在使用 state_machine gem,我想存储每个状态转换。

是否只是创建一个名为 MyClassTransition 的新模型,带有一个 transition:string from_state:state ?并在过渡时的新表中添加新记录?

是否有更好的做法来存储这些转换?我需要一种日志...

欢迎任何建议。

4

2 回答 2

1

与其自己发明这个,不如看看像papertrail这样的东西。这是我们用来记录所有更改的工具,它允许您回滚。

Railscasts 上有一个很棒的教程:

http://asciicasts.com/episodes/255-undo-with-papertrail

于 2012-12-04T22:25:33.103 回答
1

You might also want to have a look at this: https://github.com/wvanbergen/state_machine-audit_trail

Unlike Papertrail, it only log the state attribute and doesn't support rollback/undo/revert. If you don't need a rollback, it's more simpler.

And sometimes you're using before/after_transition callbacks that affect other models, you can't leverage Papertrail's rollback system.

于 2013-07-29T09:05:28.060 回答