Cubus Arts Blog

@ Gabriel Târnovan
Gabriel Târnovan

Simple Audit for Rails Apps

Gabriel Târnovan

simple_audit is a lightweight auditing solution for Rails apps. Instead of auditing all attributes of your models, simple_audit allows you to specify what data is relevant for auditing. This simple idea makes auditing complex model aggregations (through has_many, has_one, habtm associations) trivial.

Audit in 2 minutes:

Result will look like this:
Screenshot of helper result

Why ?

simple_audit is intended as a straightforward auditing solution for complex model associations. In a normalized data structure (which is usually the case when using SQL), a core business model will aggregate data from several associated entities. More often than not in such cases, only the core model is of interest from an auditing point of view (the parent in the has_xxx relations).

One approach would be to audit all aggregated entities sepparately. The downside of this is the high complexity of retracing all changes triggered on each save. Another minus is the increased database workload.

simple_audit takes a simpler approach: you decide for each audited model what data needs to be audited by specifying a serializable representation of all relevant information – including the any relevant aggregated entities (e.g. the housing_unit_bookings in the above example) This data will be serialized on every save. The available helper methods will render a clear audit trail (see above).

Limitations

This is not a solution for versioning. Changed data can not be restored. Use acts_as_audited or acts_as_versioned for that.

Dependencies

The current user is assumed to be available by calling User.current You can use sentient_user or roll your own solution.

More information

Read more on the github page. Contributions are welcome!