Skip to content

Instantly share code, notes, and snippets.

@rbeene
Forked from skarayan/gist:3239546
Created August 2, 2012 18:49
Show Gist options
  • Save rbeene/3239623 to your computer and use it in GitHub Desktop.
Save rbeene/3239623 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