trim whitespace from beginning and end of string attributes

This commit is contained in:
Sebastian Serth
2021-10-08 09:26:18 +02:00
parent 423da88815
commit 6321b2edef

View File

@ -2,4 +2,15 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
before_validation :strip_strings
def strip_strings
# trim whitespace from beginning and end of string attributes
attribute_names.each do |name|
if send(name.to_sym).respond_to?(:strip)
send("#{name}=".to_sym, send(name).strip)
end
end
end
end