zabumba
zabumba

Reputation: 12422

state machine - what is the best practice to log transitions?

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

Answers (2)

baxang
baxang

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

simonmorley
simonmorley

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

Related Questions