Skip to content

Instantly share code, notes, and snippets.

@flockonus
Created November 1, 2010 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flockonus/659043 to your computer and use it in GitHub Desktop.
Save flockonus/659043 to your computer and use it in GitHub Desktop.
/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
after_filter :log_action_taken
def current_user
@current_user ||= UserSession.find.try :user
end
# ====== > Should be a plugin along with action_logger.rb
def log_action_taken
if(current_user || @warn )
stuff = {}
stuff['user_id'] = current_user.try :id
stuff['action'] = params["action"]
stuff['controller'] = params["controller"]
stuff['when'] = Time.now
stuff['warn'] = @warn.to_i # 0 in case of regular actions
stuff['obs'] = @action_obs.to_s
if @warn.to_i > 0
stuff['ip'] = request.remote_ip
end
# Log actions TODO: isso ta certo?
p = params.to_hash
p.delete('action')
p.delete('controller')
stuff['params'] = "#(#{p.to_json})" if p.size > 0
ActionLogger.add( "(#{stuff.to_json})" )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment