Class: CustomAttributes::Unbounded
- Defined in:
- lib/custom_attributes/field_types/unbounded.rb
Overview
This class is only to be extended by types that need length validation
Direct Known Subclasses
Instance Method Summary collapse
Methods inherited from FieldType
#after_save_custom_value, available_types, #before_custom_field_save, #cast_custom_value, #cast_single_value, #cast_value, #edit_tag, find, #label, #name, #possible_custom_value_options, #possible_values_options, #set_custom_field_value, #validate_custom_field, #validate_custom_value, #value_from_keyword
Instance Method Details
#validate_single_value(custom_field, value, customizable = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/custom_attributes/field_types/unbounded.rb', line 4 def validate_single_value(custom_field, value, customizable = nil) errs = super value = value.to_s if custom_field.min_length && value.length < custom_field.min_length errs << ::I18n.t('activerecord.errors.messages.too_short', count: custom_field.min_length) end if custom_field.max_length && custom_field.max_length > 0 && value.length > custom_field.max_length errs << ::I18n.t('activerecord.errors.messages.too_long', count: custom_field.max_length) end errs end |