# Call\_backs, session data, controllers, oh my

**URL:** <https://www.ruby-forum.com/t/call-backs-session-data-controllers-oh-my/138023>\
**Category:** Rails\
**Created:** [May 19, 2008, 4:28pm UTC](https://www.ruby-forum.com/t/call-backs-session-data-controllers-oh-my/138023 "2008-05-19T16:28:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![predhme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@predhme](https://www.ruby-forum.com/u/predhme)\
**Post date:** [May 19, 2008, 4:28pm UTC](https://www.ruby-forum.com/t/call-backs-session-data-controllers-oh-my/138023/1 "2008-05-19T16:28:23Z")

</div>

I have three models…

User  
Log Items  
Requests

The relationships are built so that a user can have many requests but  
a request belongs to one user. A request has many log items and a log  
item belongs to one request.

What I want to do is log all changes made to a request so I can  
generate a time line of events. For example, when a user creates a  
request there should be a log item created with the time, request id,  
and user id. Same goes for when a request is updated. Who, when, and  
what (i use the new “dirty objects” in rails edge for the what). A log  
item has an action\_type which differentiates an update from a create  
from an assigned, etc.

I have the what and whens down pat. after\_create and before\_update  
works awesome. Now enters my issue. I track the user in the session  
(:user\_id). I know that the model is unaware (as it should be) of  
session data. Its the controllers job. But how in the world do I  
inform my call\_backs of the user\_id? Is there a more elegant way to  
tackle this issue? I was going to write a method to handle this in the  
model and just pass the user\_id to it, but I cannot create a log item  
for a request that doesn’t exist yet because it has no id. Hence why  
the after\_create is so cool. Suggestions?
