# Keeping track of who did what

**URL:** <https://www.ruby-forum.com/t/keeping-track-of-who-did-what/185888>\
**Category:** Rails\
**Created:** [March 28, 2010, 2:31pm UTC](https://www.ruby-forum.com/t/keeping-track-of-who-did-what/185888 "2010-03-28T14:31:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugenio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ec9cab/32.png) [@eugenio](https://www.ruby-forum.com/u/eugenio)\
**Post date:** [March 28, 2010, 2:31pm UTC](https://www.ruby-forum.com/t/keeping-track-of-who-did-what/185888/1 "2010-03-28T14:31:46Z")

</div>

hello everybody.  
i need to log “who did what” on some models. i was reading recipe 59  
of rails recipes and i created something like that:

class LogSweeper \< ActionController::Caching::Sweeper  
observe :model1, :model2, :model3, :model4, :model5, …

after\_save(model)  
save\_log(model, “save”)  
end

after\_destroy(model)  
save\_log(model, "destroy)  
end

private  
save\_log(model, event, user\_id = controller.session[:account\_id])  
#create the log entry, i want to save the id of the model, the id  
of the logged user and something to describe the action.  
#controller isn’t defined here so i can’t access the user\_id.  
end  
end

in environment.rb i added:  
config.active\_record.observers = :log\_sweeper

the sweeper is called when something happen to the observed models,  
but i can’t access the controller (and so, the user\_id) from there.  
any help?

---

<div class="post-metadata">

**Author:** ![eugenio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ec9cab/32.png) [@eugenio](https://www.ruby-forum.com/u/eugenio)\
**Post date:** [March 28, 2010, 6:21pm UTC](https://www.ruby-forum.com/t/keeping-track-of-who-did-what/185888/2 "2010-03-28T18:21:09Z")

</div>

Why not use one of the versioning/auditing gems (http://ruby-  
[toolbox.com/categories/activerecord\_versioning.html](http://toolbox.com/categories/activerecord_versioning.html)) instead?
