Sha256: 5c9d4c3321edef37c17f8ef703d46696ce39cc9ba3e9d8ad18c387a7df3dcb4f
Contents?: true
Size: 561 Bytes
Versions: 14
Compression:
Stored size: 561 Bytes
Contents
## # Validates a field based on the maximum length of the underlying DB field, if there is one. class DbMaximumLengthValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if defined?(Globalize) limit = record.class.translation_class.columns_hash[attribute.to_s].limit else limit = record.class.columns_hash[attribute.to_s].limit end value = record[attribute.to_sym] if value && limit && value.to_s.length > limit record.errors.add(attribute.to_sym, :too_long, count: limit) end end end
Version data entries
14 entries across 14 versions & 2 rubygems