I have a rails application with an administration interface that allows a user CRUD operations on certain models. The client wants a way to log what user does what to each model. For example, A user deletes a customer etc. He would like to track who deleted/updated/created that customer. I’m pondering the best way to handle this. I’m also curious if there is a gem out there that already does this.
Here’s my thinking.
- I could have a created_by and updated_by field in each Model. The problem
is tracking deleted_by. One Method is to mark the Customer inactive
instead of deleting the actual record. Seems cumbersome and there
would be a lot of repetition in each and every model I want to
track. -
I could create an event_history model that tracked the following fields (class diagram below). The model_record_data field could be stored as an array or object possibly? Can you store objects in a mysql field as text? The benefits of this method, to me is that I can call to this Model and store actions from any model I create in the future. In addition I can restore a record to a previous state if someone makes a mistake.
event_history -> model_name model_record_data action #create/update/delete etc action_date #datetime user_id
I would appreciate some feedback on this and your help would be appreciated.
Take a look at this gem (
audited). I believe it does what are asking.https://github.com/collectiveidea/audited