Reputation: 12422
I am using state_machine gem and I'd like to store every state transition.
Is it just a matter of creating a new model called MyClassTransition with a transition:string from_state:state ? and add new record in that the new table on transition?
Is there a better practice to store these transition? I need a kind of a log ...
Any recommendations are welcome.
Upvotes: 0
Views: 1427
Reputation: 3807
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.
Upvotes: 1
Reputation: 2804
Instead of inventing this yourself, why don't you look at something like papertrail. This is what we use to record all our changes and it allows you to rollback.
There's a great tutorial on Railscasts:
http://asciicasts.com/episodes/255-undo-with-papertrail
Upvotes: 1