Created
November 9, 2010 05:17
-
-
Save matthuhiggins/668734 to your computer and use it in GitHub Desktop.
Where to put the other files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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