We maybe need a quantity validator beside the current validates_length_of?

I was talking with @sgrif about this in this
ticket Length validator only working with strings? · Issue #19570 · rails/rails · GitHub.

I think the current validates_length_of is pretty fine expressing thinks
like “the username is too long”, and the tokenizer is ideal for strings
situations but when it comes to arrays, collections, etc is really
to override the message error and not being able to use some kind of

I did this gist to test this out

I was using this validator to thinks like:

validates_count_of :photos, within: 1…3, selector: ->(photos) {
photos.reject(&:marked_for_destruction?) }

This allows to have new errors.messages keys to express quantity:


Anyone shares this point of view?

at first glance it seems reasonable

Sent from my iPhone