Mr_Nizzle
Mr_Nizzle

Reputation: 6714

How to validate a field value at activeRecord model in Ruby on Rails?

is there something like:


validates_value_of :verified,:with=>1

to validate the boolean field on the model?

Upvotes: 3

Views: 2041

Answers (2)

iain
iain

Reputation: 16284

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

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

Upvotes: 5

True Soft
True Soft

Reputation: 8796

See validates_inclusion_of:

validates_inclusion_of :verified, :in => [1]

in your case

Upvotes: 2

Related Questions