Out-cheat validates_uniqueness_of

before_save :strip_strings

 validates_uniqueness_of :username
 validates_presence_of :username

 private

 def strip_strings
     self.username = username.gsub!(" ","")
 end

example:

username = " [email protected] "

becomes [email protected]
and is stored in the datbase as [email protected]

“gissmoh @gissmoh. de”

becomes [email protected]
and is stored in the datbase as [email protected]

So I have duplicate entries!!

use before_validation : strip_strings instead

before_save occurs before Base.save, but after the validation

Jean-Etienne
http://www.woa.hu

Jean-Etienne D. schrieb:

use before_validation : strip_strings instead

before_save occurs before Base.save, but after the validation

Hit! It works!! Thanx…

I think there’s still a lot to learn…puuuuh!!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs