2

I'm using the Workflow gem (https://github.com/geekq/workflow) in my Rails App as a state machine. As an object passes through various states, I'd like to record the datetime when it changes, but not too sure if that's so straightforward.

One approach I may take is one extra column called 'workflow_state_date_changed', and update this column whenever the state changes - this was I could see how long the object has been in a particular state. What it won't allow, however, is to historically look at all the states it past through, and the time spent in each. Any thoughts of a way of achieving this in a fairly light way?

Look forward to hearing from you.

idrysdale
  • 1,551
  • 2
  • 12
  • 23

3 Answers3

0

You can use ActiveRecord::Observer to record events on attributes. If you use StateMachine it supports observation on different methods like after_transition. I don't know how Observer can be used with workflow

Rahul Tapali
  • 9,887
  • 7
  • 31
  • 44
0

I ended up building a solution from scratch, following Ryan Bate's excellent screencast at:

http://railscasts.com/episodes/392-a-tour-of-state-machines?view=asciicast

idrysdale
  • 1,551
  • 2
  • 12
  • 23
0

use state_machine gem it very powerful and you can do it very easy

https://github.com/pluginaweek/state_machine

achr3f
  • 150
  • 8
  • I actually ended up writing my own functions. Originally I was put off state_machine as it's over 3,000 lines of code and I try to be mindful of using big gems when I only end up using them once or twice. – idrysdale Aug 13 '13 at 12:14
  • :) good but always it's depend of your state machine and the complexity of transitions between events, – achr3f Aug 13 '13 at 12:20