0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

booleanのvalidateについて

Posted at

booleanのカラムについて、バリデーションをかけたがvalid?がtrueにならず、期待していた実行とは違うものになってしまった!

そこで、booleanのカラムについて調べたことを備忘録としてまとめておく!

ダメなパターン:Notnull制約でfalseが入っているので、presence: trueをすれば良いと思い下記のようにした!

validates :check, presence: true

しかし、これだとcheck=falseの時にエラーが出てしまう!

調べてみると、下記のようにする必要があることがわかった!

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

参考資料
https://qiita.com/mktakuya/items/a13c2175f0f0d9871038

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?