Sha256: 0a55c50efa1d87595ee5c30ac9f96b814bc3a90030f4a2fafe80579210b4106b

Contents?: true

Size: 614 Bytes

Versions: 10

Compression:

Stored size: 614 Bytes

Contents

# 
# If a field is nullable and if user hits spacebar a few times and submits
# the form then ActiveRecord would have the value as empty spaces.
#
# Following fix would remove all leading and trailing white spaces from a string value.
# And if the value is empty space then it will be set to nil.
#
# It would result in value being saved as NULL if user passed only a few white spaces.
#
module ActiveRecord
  class Base
    before_validation do |record|
      record.attributes.each do |attr, value|
        record[attr] = value.blank? ? nil : value.strip if value.respond_to?(:strip)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nimbleshop_core-0.0.3 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.2 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.2.beta1 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.1 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.1.rc6 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.1.rc5 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.1.rc4 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.1.rc3 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.1.rc2 lib/nimbleshop/core_ext/activerecord_base.rb
nimbleshop_core-0.0.1.rc1 lib/nimbleshop/core_ext/activerecord_base.rb