Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Monitoring in Rails

We have an app with an extensive admin section. We got a little trigger happy with features (as you do) and are looking for some quick and easy way to monitor "who uses what".

Ideally a simple gem that will allow us to track controller/actions on a per user basis to build up a picture of the features that are used and those that are not.

Anything out there that you'd recommend..

Thanks

Dom

like image 207
Dom Avatar asked Sep 23 '08 09:09

Dom


1 Answers

I don't know that there's a popular gem or plugin for this; in the past, I've implemented this sort of auditing as a before_filter in ApplicationController:

from memory:

class ApplicationController < ActionController::Base
  before_filter :audit_events
  # ...

  protected
  def audit_events
    local_params = params.clone
    controller = local_params.delete(:controller)
    action = local_params.delete(:action)
    Audit.create(
      :user => current_user, 
      :controller => controller, 
      :action => action, 
      :params => local_params
    )
  end
end

This assumes that you're using something like restful_authentication to get current user, of course.

EDIT: Depending on how your associations are set up, you'd do even better to replace the Audit.create bit with this:

current_user.audits.create({
  :controller => controller,
  :action => action,
  :params => local_params
})

Scoping creations via ActiveRecord assoiations == best practice

like image 172
Ben Scofield Avatar answered Nov 01 '22 17:11

Ben Scofield