On 8/30/07, Marc B. [email protected] wrote:
I would like to create audit tables in my RoR/mysql app. I would like to
start out auditing just about everything: every change in the database
should result in a row in (one or more) audit tables. My app requires
login, so I would like to include the user_id in all entries.
Is there a good starting point for this or should I simply design the
table(s), build triggers, etc.?
You need to learn about AR’s callbacks
which are “hooks” where you can add the auditing code.
Also, google for “rails created_by” for some articles related to the
issue of getting the user id. It’s not as easy as it looks, because
the model code (where the callbacks are) doesn’t really have access to
the controller (where the user id is). It can be done (I’m doing it),
but you need to read up on the various considerations, especially