Auditing: session[:user] reference in after_save callback

Chris Dekker
2008-04-23T21:01:16Z

I know, it is against the MVC to speak directly to a session object in
the model but I am looking for a solution to this problem with auditing

I have a SystemLog model which works as a sort of auditor to track
changes. It has a user_id that references the user that initiated the
change and a text string with a description and some other columns.

Whenever I save a model, i want to create a SystemLog object with values
I can get from the model that is being saved itself, except for the
user_id.

How am I supposed to get the session[:user] data neatly to the model the
way Ruby wants it to? Or is there any other way to realise this auditing
process which I am overlooking?

The alternative violates the DRY philosophy. After every call to
@object.save in the controller I manually create a new SystemLog object
with the @object''s attributes and session[:user] variable.
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org