before_save, strip a string

before-filter, before-save, ruby-on-rails, ruby-on-rails-4

Solution

You'd rather update the setter instead of polluting your model with callbacks:

def username=(value)
  self[:username] = value.to_s.strip
end

Btw, I prefer `squish`

Problem

I'm trying to `strip` the whitespaces of the variable `Username` in my User Model. I'm using ``` before_save do self.username.strip! end ``` but it doesn't seem to work, am i missing something ?

Original source