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

randomutterings...
2008-04-24T14:24:01Z

Use an attr_accessor in your model.

attr_accessor :user_id
after_save :audit

def audit
  @systemlog = SystemLog.new
  @systemlog.user_id = self.user_id
end


On Apr 23, 6:01 pm, Chris Dekker
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> sw0rdfish wrote:
> > 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...@andreas-s.net>
>
> Thats the plan yeah. But the thing is I want need the logged in user
> (from the session in my MODEL, since this is the only place I can call
> my before_ and after_save functions.
>
> So the hard part is getting the ID from the session to the Model, since
> this is not really Ruby''s way of doing it.
> --
> Posted viahttp://www.ruby-forum.com/.