module ActiveModel
validates each member element of an array attribute
by default will allow only the first error per validator, regardless of how many elements might fail validation. this improves performance as well as averting a large number of repeating error messages. use multiple_errors: true on :array or a single sub-validator to enable the full set of errors. this is potentially useful if each error message will vary based upon the array element's contents.
usage:
validates :tags, array: { format: /\A[^aeiou]*\z/, length: 5..10 } validates :permissions, array: { multiple_errors: true, format: /\A[^aeiou]*\z/ }
the :if, :unless, and :on conditionals are not supported on sub-validators, but do work as normal on the :array validator itself.
validates :permissions, if: :this_condition_works, array: { if: :this_condition_applies_to_permissions_but_not_each_element, inclusion: { in: %w(one two), unless: :conditions_on_subvalidators_are_ignored } }
validates each key of a hash attribute
by default only allows the first error per validator, regardless of how many keys fail validation. this improves performance and avoids a bunch of repeating error messages. use `multiple_errors: true` on :hash_keys or a single sub-validator to enable the full set of errors. this is potentially useful if each error message will vary based upon each hash key.
the :if, :unless, and :on conditionals are not supported on sub-validators, but do work as normal on the :hash_keys validator itself.
usage:
validates :subjects, hash_keys: { format: /\A[a-z]+\z/, # multiple_errors: true }
validates each value of a hash attribute
by default only allows the first error per validator, regardless of how many values fail validation. this improves performance and avoids a bunch of repeating error messages. use `multiple_errors: true` on :hash_values or a single sub-validator to enable the full set of errors. this is potentially useful if each error message will vary based upon each hash value.
the :if, :unless, and :on conditionals are not supported on sub-validators, but do work as normal on the :hash_values validator itself.
usage:
validates :subjects, hash_values: { length: 3..100, # multiple_errors: true }