granth green sumo

turkey sandwiches!

Photo Photo Photo Photo Photo Photo

Strip Whitespace 2 February 2006

rails

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! }
end

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

previously: Shopping Cart #10