class Person
before_validation :strip_blanks
protected
def strip_blanks
self.name = self.name.strip
end
end
The source of this snippet contains some discussion about why this is not The default Rails behavior. http://www.ruby-forum.com/topic/166426
Suppose I implement validates_uniqueness_of on the username. If the name’maddy’ is already Exists, then it will accept the value’maddy’ as the only value instead of’maddy’. It should remove the spaces on both sides. How can there be this behavior?
class Person
before_validation :strip_blanks
protected
def strip_blanks
self .name = self.name.strip
end
end
The source of this snippet contains some discussion as to why this is not the default Rails behavior. http://www.ruby -forum.com/topic/166426