D
D
deadvip2012-10-26 19:37:04
Ruby on Rails
deadvip, 2012-10-26 19:37:04

Logging data from the session?

There was a need to add the current user to the log. From many models, data is written to the log in the filters after_create, after_update (therefore, it will not work to transfer the session object from the controller), there is no access to the session from the model. There is an option with Thread.current[:current_user] = session[bla-bla] and this variable is available in the model, but as far as I understand, this only works for the Mongrel server, since a separate thread is created for each user - I haven’t tried it. I don’t really want to catch all the places where the creation / update takes place and write the log from the controllers (there are too many of them + you will have to add them manually in the future). Are there solutions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsespb, 2012-10-26
@vsespb

Database callbacks after_create, after_update are best used only for working with the model itself (and the database) and not interacting with the outside world, because this is a violation of MVC. Otherwise, in my experience, there are problems worse than yours.
Even ActiveRecord::Observer is probably not worth using.
subj is discussed here and there are some kind of hacks to write a session from the model to the log
pjkh.com/articles/2009/02/02/creating-an-audit-log-in-rails
stackoverflow.com/questions/133558/good- idea-to-access-session-in-observer-or-not
www.zorched.net/2007/05/29/making-session-data-available-to-models-in-ruby-on-rails/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question