I have three models…
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?