ruby - Rails model: validates_uniqueness_of doesn't remove trailing spaces not leading ones before unique check? -
Suppose that I implement validates_uniqueness_of in the name of the user if the name 'madi' already exists, then the value 'Madi' will accept it as a unique value, but not 'Medie'. This blank space should be removed from both sides. How is this behavior done?
before person_validation class: strip_blanks protected def strip_blanks self.name = self.name.strip End of End There is some discussion in the source of this snippet why it is not the default rail behavior
Comments
Post a Comment