search for: empty_to_nil

Displaying 1 result from an estimated 1 matches for "empty_to_nil".

2006 May 02
4
useful bit of code (hopefully)
...it: ########### # fix user input before validating it before_validation :sanitize_input # santize input before actual validation is called # this uses the little methods defined below def sanitize_input trim %w(adres postcode woonplaats email naam telefoon mobiel) downcase :email empty_to_nil %w(telefoon mobiel) end # pass in a list of fields whose values will be converted to nil # you should only use these on objects that respond to empty? # if the value is empty (this causes empty strings '''' to become nils) def empty_to_nil(fields) fields.to_a.each {|f| self[f] =...