granth green sumo

turkey sandwiches!

Photo Photo ⛴ :sunrise: Photo Photo Photo

Strip Whitespace 2 February 2006


Remove leading and trailing whitespace from a model’s fields:

def before_validation
  attributes.each_key {|a| self[a].strip! if self[a].respond_to? :strip! }

I also found a more complicated version, implemented as an Observer, on the Rails wiki.

previously: Shopping Cart #10