Yet another thread on boolean validations

9 views
Skip to first unread message

Justin Kenyon

unread,
Feb 4, 2020, 6:44:04 PM2/4/20
to Ruby on Rails: Core
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.
Reply all
Reply to author
Forward
0 new messages