Ruby – Rails Model: Validates_Unique Ness_OF Will not delete the endless space before a unique check? Isn’t the front guide?

Suppose I implement validates_uniqueness_of on the username. If the name’maddy’ already exists, then it will accept the value’maddy’ as the unique value instead of’maddy’. It should remove both sides The spaces. How can this behave?
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

Leave a Comment

Your email address will not be published.