Created
March 20, 2012 19:17
Adding functionality to every model in a system
This file contains 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
# 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 |
This file contains 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
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