Sha256: 520616e92e882749dbde5a83e92c29ec5a3c1287912ecf517acc3fad1ca5d0c8
Contents?: true
Size: 585 Bytes
Versions: 89
Compression:
Stored size: 585 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 = if defined?(Globalize) record.class.translation_class.columns_hash[attribute.to_s].limit else 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
89 entries across 89 versions & 1 rubygems