About boolean validate

I validated the boolean column, but valid? Didn't become true, and it wasn't what I expected!

Therefore, I will summarize what I researched about boolean columns as a memorandum!

Bad pattern: Not null constraint contains false, so I thought I should do presence: true, so I did the following!


validates :check, presence: true

However, in this case, an error occurs when check = false!

After some research, I found that I needed to do the following!


validates :check, inclusion: {in: [true, false]}

Reference material https://qiita.com/mktakuya/items/a13c2175f0f0d9871038

Recommended Posts

About boolean validate
About =
About method.invoke
About Kotlin
About attr_accessor
About Hinemos
About inheritance
About Docker
About Rails 6
About Spring ③
About enum
About polymorphism
About Optional
About hashes
About JitPack
About this ()
About encapsulation
About exceptions
About scope
[Maven] About Maven