Sha256: 3d674716b9cc4f2eacb1dd8fb047031c54c17deda2bd72afd784afdfcdfbbe1a
Contents?: true
Size: 435 Bytes
Versions: 30
Compression:
Stored size: 435 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) limit = record.class.columns_hash[attribute.to_s].limit 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
30 entries across 30 versions & 1 rubygems