# Validates acceptance of question

**URL:** <https://www.ruby-forum.com/t/validates-acceptance-of-question/154693>\
**Category:** Rails\
**Created:** [December 3, 2008, 1:12am UTC](https://www.ruby-forum.com/t/validates-acceptance-of-question/154693 "2008-12-03T01:12:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 3, 2008, 1:12am UTC](https://www.ruby-forum.com/t/validates-acceptance-of-question/154693/1 "2008-12-03T01:12:54Z")

</div>

I have a terms of service agreement attached to a checkbox. It seems  
to work ok and I see

“agreement”=\>“0” when the box is not checked in the development log

and

“agreement”=\>“1” when the box is checked in the log.

But in the model I this validation:

validates\_acceptance\_of :agreement,  
:message =\> “Please accept the terms to  
proceed”

So when the form is actually filled out, no matter whether the box is  
checked or not I get:

1 error prohibited this agent from being saved

There were problems with the following fields:

-Agreement, Please accept the terms to proceed

So what am I missing to get this to work?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 3, 2008, 4:27am UTC](https://www.ruby-forum.com/t/validates-acceptance-of-question/154693/2 "2008-12-03T04:27:45Z")

</div>

> There were problems with the following fields:
> 
> -Agreement, Please accept the terms to proceed
> 
> So what am I missing to get this to work?

is :agreement a field in your database? if so the docs say…

:accept - Specifies value that is considered accepted. The default  
value is a string “1”, which makes it easy to relate to an HTML  
checkbox. This should be set to true if you are validating a database  
column, since the attribute is typecast from “1” to true before  
validation.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 3, 2008, 7:06am UTC](https://www.ruby-forum.com/t/validates-acceptance-of-question/154693/3 "2008-12-03T07:06:50Z")

</div>

Yes, :agreement is a field in my database. Should I remove it?  
In any case I did set the :accept =\> “true”, but it didn’t change  
anything. I get the same error when I submit the form whether or not  
the box is checked.  
The html shows:

Am I reading this right that after the checkbox value is set to “1”  
that then there is a hidden value that is setting it to “0”? Is this  
supposed to be this way?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 3, 2008, 6:37pm UTC](https://www.ruby-forum.com/t/validates-acceptance-of-question/154693/4 "2008-12-03T18:37:15Z")

</div>

On Dec 2, 2008, at 10:05 PM, removed\_email\_address@domain.invalid wrote:

> Yes, :agreement is a field in my database. Should I remove it?  
> In any case I did set the :accept =\> “true”, but it didn’t change  
> anything. I get the same error when I submit the form whether or not  
> the box is checked.

Set :accept =\> true (no quotes). That’s how I read the docs… if  
it’s a database column, you need that.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 4, 2008, 1:43am UTC](https://www.ruby-forum.com/t/validates-acceptance-of-question/154693/5 "2008-12-04T01:43:23Z")

</div>

Thanks for your help. That was it. Remove the quotes and it works.
