Thanks much, that worked. I appreciate it. On Aug 4, 6:00 pm, "Stefan Lang" <perfectly.normal.hac...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 2008/8/4 predhme <ken...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > Hello, > > > I have three models setup as such.... > > > User > > has_many :requests > > > Request > > has_many :changes > > > Changes > > belongs_to :request > > belongs_to :who, :class_name => "User", :foreign_key => "user_id" > > > A user logs into the system and the id is stored in the session... > > Whenever a user creates or edits a request I want an entry created in > > the changes table. Basically spelling the who, what, and when... > > > I have everything working how I want except the "who" part... I am > > unsure of an elegant approach. I am using the after_* methods, but the > > session is inaccessible to the model (as it should be)... How can I > > (the rails way) log the user_id for the change? > > I''ve solved exactly that by adding a User.current_user attribute > that is set in an "authorize" before_filter that is run for every > request. If you want that to be threadsafe, you can store the > current user in Thread.current[:_my_app_current_user] (but I''d > define User.current_user as a facade anyway). > > Stefan--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---