Module: CampfireLogic::Base::ClassMethods
- Defined in:
- lib/campfire_logic.rb
Instance Method Summary collapse
-
#trimmed_fields(*field_list) ⇒ Object
Register a before-validation handler for the given fields to trim leading and trailing spaces.
Instance Method Details
#trimmed_fields(*field_list) ⇒ Object
Register a before-validation handler for the given fields to trim leading and trailing spaces.
Adapted from scottmoonen.com/2009/05/08/rails-pattern-trim-spaces-on-input/
22 23 24 25 26 27 28 |
# File 'lib/campfire_logic.rb', line 22 def trimmed_fields *field_list before_validation do |model| field_list.each do |n| model[n] = model[n].strip if model[n].respond_to?(:strip) end end end |