Model after_* methods


I have three models setup as such....

   has_many :requests

   has_many :changes

   belongs_to :request
   belongs_to :who, :class_name => "User", :foreign_key => "user_id"

A user logs into the system and the id is stored in the session...
Whenever a user creates or edits a request I want an entry created in
the changes table. Basically spelling the who, what, and when...

I have everything working how I want except the "who" part... I am
unsure of an elegant approach. I am using the after_* methods, but the
session is inaccessible to the model (as it should be)... How can I
(the rails way) log the user_id for the change?

I've solved exactly that by adding a User.current_user attribute
that is set in an "authorize" before_filter that is run for every
request. If you want that to be threadsafe, you can store the
current user in Thread.current[:_my_app_current_user] (but I'd
define User.current_user as a facade anyway).


Thanks much, that worked. I appreciate it.