I am trying to strip spaces of the Username variable in my user model.
strip
Username
I use
before_save do self.username.strip! end
but it doesnβt seem to work, am I missing something?
You would prefer to update the installer instead of polluting your model with callbacks:
def username=(value) self[:username] = value.to_s.strip end
Btw, I prefer squish
squish
If you want to remove only the leading and trailing white space, you can use .strip!
But as you said:
I am trying to remove the spaces of the username variable in my user model.
I think that in fact you want to remove all spaces , the following should do:
.gsub(/\s+/, "")
EDIT:
Oh yes, you can also use the built-in Rail squish() method
squish()
thanx for apneadiving for reminder