Forum: Ruby on Rails how to pass info external to model to after_create callback

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-27 19:45
(Received via mailing list)
I've got a situation where i have a model that whenever something
changes i want to drop a row in another table (audits) to indicate
that the record changed and who changed it.  currently whenever i save
the data i make a call to the models audit method and pass in a User

keep in mind that the model i am auditing does not reference a user,
which is why i have to pass in the User object to the audit call.

anyways, i want to add after_create and before destroy callbacks to
the model but I am hung up on how to pass the User object via the

8da92d4ed91aa12535f6d870fa76b25e?d=identicon&s=25 Aaron (Guest)
on 2007-02-27 20:57
(Received via mailing list)

Take a look at the documentation on observers:

You may find this helpful, especially if you want to have an audit
trail on more than one table.  You can pass the user to the model
using Thread.current:

Thread.current[:user] = your_user

The Rails Recipes book has an audit trail recipe ("Keeping Track of
Who Did What") that uses a cache sweeper that may give you some ideas.

This topic is locked and can not be replied to.