Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created October 27, 2009 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/219579 to your computer and use it in GitHub Desktop.
Save metaskills/219579 to your computer and use it in GitHub Desktop.
module AttrStripper
module Stripper
def self.included(base)
base.alias_method_chain :write_attribute, :attr_stripper
end
def write_attribute_with_attr_stripper(attr, value)
value = value.dup.strip if value.is_a?(String)
write_attribute_without_attr_stripper(attr,value)
end
end
end
ActiveRecord::Base.send :include, AttrStripper::Stripper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment