Created
August 16, 2009 19:00
-
-
Save boosty/168706 to your computer and use it in GitHub Desktop.
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
# Include me in your ActiveRecord model and get string attributes | |
# trimmed/stripped before validation. | |
module TrimStringAttributes | |
def self.included(base) | |
base.class_eval <<-EOF | |
before_validation :trim_string_attributes | |
EOF | |
end | |
protected | |
def trim_string_attributes | |
attributes.each do |k,v| | |
self[k] = v.mb_chars.strip if v.respond_to?(:mb_chars) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment