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
validates :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.