# User stamping and Authlogic

**URL:** <https://www.ruby-forum.com/t/user-stamping-and-authlogic/183501>\
**Category:** Rails\
**Created:** [February 15, 2010, 6:43pm UTC](https://www.ruby-forum.com/t/user-stamping-and-authlogic/183501 "2010-02-15T18:43:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marnen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@marnen](https://www.ruby-forum.com/u/marnen)\
**Post date:** [February 15, 2010, 6:43pm UTC](https://www.ruby-forum.com/t/user-stamping-and-authlogic/183501/1 "2010-02-15T18:43:03Z")

</div>

[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.]

Hi folks.

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  
following options:

- 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?

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![marnen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@marnen](https://www.ruby-forum.com/u/marnen)\
**Post date:** [February 16, 2010, 11:26am UTC](https://www.ruby-forum.com/t/user-stamping-and-authlogic/183501/2 "2010-02-16T11:26:46Z")

</div>

I’ve been pondering how to do user stamping lately too, event though I  
dont need to keep a trail like you do. I dont want to make current\_user  
available to all models, and I dont want to use Thread.current.  
I’ve been thinking about using this:  
[http://railstips.org/blog/archives/2008/10/17/who-done-what-a-k-a-user-stamping/](http://railstips.org/blog/archives/2008/10/17/who-done-what-a-k-a-user-stamping/)

“Eventually, we decided on a sweeper as they have access to controllers  
which would have access to the current user”

Maybe that solution gives you some ideas?

---

<div class="post-metadata">

**Author:** ![marnen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/67e7ee/32.png) [@marnen](https://www.ruby-forum.com/u/marnen)\
**Post date:** [February 16, 2010, 5:08pm UTC](https://www.ruby-forum.com/t/user-stamping-and-authlogic/183501/3 "2010-02-16T17:08:34Z")

</div>

Sharagoz – wrote:

> I’ve been pondering how to do user stamping lately too, event though I  
> dont need to keep a trail like you do. I dont want to make current\_user  
> available to all models, and I dont want to use Thread.current.  
> I’ve been thinking about using this:  
> [Who Done What? a.k.a. User Stamping // RailsTips by John Nunemaker](http://railstips.org/blog/archives/2008/10/17/who-done-what-a-k-a-user-stamping/)
> 
> “Eventually, we decided on a sweeper as they have access to controllers  
> which would have access to the current user”
> 
> Maybe that solution gives you some ideas?

Thanks for pointing me back to that. I’d looked at that page briefly,  
but not really read it in detail. I think that if I add an updated\_by  
field to my model, I should be able to use that plugin out of the box  
along with my version control gem (probably acts\_as\_revisable).

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
