We maybe need a quantity validator beside the current validates_length_of?

21 views
Skip to first unread message

mmon...@museways.com

unread,
Mar 30, 2015, 3:05:33 AM3/30/15
to rubyonra...@googlegroups.com
I was talking with @sgrif about this in this ticket https://github.com/rails/rails/issues/19570.

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 strange to override the message error and not being able to use some kind of selector.


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:

errors.messages.too_many
errors.messages.too_few
errors.messages.wrong_count

Anyone shares this point of view?

Dmitry Shvetsov

unread,
Mar 31, 2015, 6:41:05 PM3/31/15
to rubyonra...@googlegroups.com
at first glance it seems reasonable

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4fbcca9f-1cc6-4fae-bb4a-fd482021bcf4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages