Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Created August 3, 2011 07:14
Show Gist options
  • Save hopsoft/1122080 to your computer and use it in GitHub Desktop.
Save hopsoft/1122080 to your computer and use it in GitHub Desktop.
Rails Environment Based Behavior
# app/models/user.rb
class User < ActiveRecord::Base
end
# lib/user_logger.rb
module UserLogger
def self.included(mod)
mod.send :after_create, :log_creation
end
protected
def log_creation
Log.new_user(self)
end
end
# config/environments/production.rb
User.send(:include, UserLogger)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment