-
-
Save rbeene/3239623 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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