Skip to content

Instantly share code, notes, and snippets.

@rahearn
Created March 20, 2012 19:17
Show Gist options
  • Save rahearn/2140071 to your computer and use it in GitHub Desktop.
Save rahearn/2140071 to your computer and use it in GitHub Desktop.
Adding functionality to every model in a system
# This file is in lib
module AutoStripTextAttributes
extend ActiveSupport::Concern
included do
text_columns = columns.collect do |c|
c.name.to_sym if c.type == :string || c.type == :text
end.compact
auto_strip_attributes(*text_columns) unless text_columns.empty?
end
end
require 'auto_strip_text_attributes'
# This file is in config/initializers
module ActiveRecordModelTracker
def inherited(by_our_model)
by_our_model.__send__ :include, AutoStripTextAttributes
super
end
end
ActiveRecord::Base.extend ActiveRecordModelTracker unless $rails_rake_task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment