Re: Auditing: session[:user] reference in after_save callback

sw0rdfish
2008-04-23T21:16:40Z

I''m probably mis-understanding the question, but is the problem you
want information about the user logged in?  Could you not do a Find on
the user table using the ID of the user saved in the [:session] ?

On Apr 23, 5:01 pm, Chris Dekker
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> 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 viahttp://www.ruby-forum.com/.