I'm updating this older thread based upon my recent experience. This
will not call strip on nils, fixnums, etc.
before_save :strip_whitespace
def strip_whitespaces
@attributes.each do |attr,value|
self[attr] = value.strip if value.is_a?(String)
end
end
I'm updating this older thread based upon my recent experience. This
will not call strip on nils, fixnums, etc.
before_save :strip_whitespace
def strip_whitespaces
@attributes.each do |attr,value|
self[attr] = value.strip if value.is_a?(String)
Might also try...
self[attr] = value.strip if value.respond_to?(:strip)
... to pick up things that aren't strings, but are string like.