This blog is part of our Rails 5 series.
validates_acceptance_of is a good validation tool for
asking users to accept
“terms of service” or similar items.
Before Rails 5, the only acceptable value for a
validates_acceptance_of validation was
Having acceptable value of
1 does cause some ambiguity
because general purpose of acceptance validation is for attributes that hold boolean values.
So in order to have
true as acceptance value we had to
accept option to
validates_acceptance_of as shown below.
Now this comes with the cost that
is no longer an acceptable value.
In Rails 5, we have
true as a
default value for acceptance
along with the already existing acceptable value of
In Rails 5 the previous example would look like as shown below.
Rails 5 allows user to have custom set of acceptable values
In Rails 5,
:accept option of
validates_acceptance_of method supports an array of values
unlike a single value that we had before.
So in our example if we are to validate our
terms_of_service attribute with any of
we could have our validation as follows.