Yet another thread on boolean validations

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Yet another thread on boolean validations

Justin Kenyon
I see there has been lots of chatter over the years on how to properly validate the presence of a boolean field.
The community has settled, rightly, on this
validates :field, inclusion: { in: [true, false] }
# or
:field, exclusion: { in: [nil] }

I'd like to suggest that we make this even better and add a `boolean` validator to allow for: 
validates :field, boolean: true

By using this method we would not only validate presence, but also the inclusion of a `true` or `false` value.

Would love to hear thoughts on this. PR incoming.

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit