Skip to content

Instantly share code, notes, and snippets.

@matthuhiggins
Created November 9, 2010 05:17
Show Gist options
  • Save matthuhiggins/668734 to your computer and use it in GitHub Desktop.
Save matthuhiggins/668734 to your computer and use it in GitHub Desktop.
Where to put the other files
module ActionControllerExtra
module UserLogger
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
# Logs that a user requested the current action:
#
# MyController < ApplicationController
# user_logger
# end
#
# The same options for ActionController::Filters are available. For example,
# to only log the user in the create and destroy actions:
#
# MyController < ApplicationController
# user_logger :only => [:create, :destroy]
# end
#
def user_logger(options = {})
include InstanceMethods
before_filter :log_user, options
end
end
module InstanceMethods
def log_user
logger.info("#{session[:username]} requested #{controller_name}/#{action_name}")
end
end
end
end
require 'rails_extensions/user_logger'
ActionController::Base.class_eval do
include ActionController::UserLogger
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment