How to check field value in activeRecord model in Ruby on Rails?

there is something like:


validates_value_of :verified,:with=>1

to test a boolean field on a model?

+3
source share
2 answers

If you want it to always be true, use validates_acceptance_of . If you want this to be either true or false, use validates_inclusion_of .

validates_acceptance_of :verified
validates_inclusion_of :verified, :in => [ true, false ]
+5
source

See validates_inclusion_of :

validates_inclusion_of :verified, :in => [1]

in your case

+2
source

Source: https://habr.com/ru/post/1779477/


All Articles