Skip to content

Instantly share code, notes, and snippets.

@skarayan
Created August 2, 2012 18:39
Show Gist options
  • Save skarayan/3239546 to your computer and use it in GitHub Desktop.
Save skarayan/3239546 to your computer and use it in GitHub Desktop.
class ActiveRecord::Base
def self.inherited(klass)
callbacks = [:before_validation, :before_save, :before_create, :before_update]
callbacks.each do |callback|
klass.send(callback) do
return unless respond_to?(:updated_by) || updated_by.nil?
self.updated_by = Thread.current[:current_user]
end
end
end
end
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_current_user
private
def current_user
# ...
end
def set_current_user
Thread.current[:current_user] = current_user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment