[I originally posted this to the Authlogic group, but since it’s more of a general Rails issue, I’m reposting it here. Since I wrote the original, I’ve been leaning more toward using Thread.current.]
I have what seems like a common problem, but I can’t seem to find a
good answer to how to do this with Authlogic. I’m writing a medical
records application, so I need a userstamped audit trail of changes to
each record and association. Oddly enough, none of the versioning
plugins for Rails take care of both the user stamping and the
association versioning, so my plan at the moment is to use
acts_as_revisable. I can figure out how to get everything done –
except make the current user available to the model so that the
version plugin can see it. As far as I can tell, there are the
- Have the model belong to User: won’t work in my use case, because
each revision could be made by a different user.
- Have a before_filter assign to User.current_user: seems simple, and
I’ve done it that way in the past, but I understand that this can run
into concurrency issues, so I’m not eager to do it this way again.
- Have a before_filter put the current user into Thread.current, so
that the whole app can see it: again, looks great, but I’m not sure
how to clean up Thread.current at the end of the request.
- Call UserSession.find directly in the model: sounds wonderfully
simple, but will it work?
What should I do here?