# Confirmation Checkboxes - any good ideas?

**URL:** <https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496>\
**Category:** Rails\
**Created:** [November 5, 2009, 2:12pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496 "2009-11-05T14:12:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 2:12pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/1 "2009-11-05T14:12:13Z")

</div>

I have a site in development that I need to customer to confirm a few  
things before they can proceed to the payment page. I intend to  
present them with the relevant questions and then check that they have  
answered them e.g. have you read the T’s & C’s. Are you over 18? Are  
you resident in the UK etc etc. I do not need to record these  
necessarily.

Is there a simple way of validating these in the controller and then  
returning the messages in the same way as Active Record would do so I  
can use the same form builder as the rest of the site (I do inline  
errors with ToolTip)?

I have considered just implementing a model called “Confirmation” with  
a 1-1 relationship with order but I think this is a little overkill  
and the number of confirmations may change over time and vary. So I  
would need a to implement a confirmation answer model and a  
confirmation question model. All seems a bit complex. How about just  
serializing a hash as a database column with the questions as the key  
and the values entered?

Has anyone got any good ideas?

Thanks,

O.

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 3:06pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/2 "2009-11-05T15:06:04Z")

</div>

My approach on things like this has been to add the attribute to the  
model with attr\_accessor, and then setting up whatever validations I  
need. E.g.

attr\_accessor :terms\_of\_service

validates\_acceptance\_of :terms\_of\_service

Seems to work fine (I’ve had issues where I’ve been passing such a model  
along a multi-action process by storing it in the session, though).

(Still not sure from a business/legal sense why you wouldn’t need these  
to be persistent attributes, however)

dwh

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/3 "2009-11-05T15:15:42Z")

</div>

Denis H. wrote:

> My approach on things like this has been to add the attribute to the  
> model with attr\_accessor, and then setting up whatever validations I  
> need. E.g.
> 
> attr\_accessor :terms\_of\_service
> 
> validates\_acceptance\_of :terms\_of\_service
> 
> Seems to work fine (I’ve had issues where I’ve been passing such a model  
> along a multi-action process by storing it in the session, though).
> 
> (Still not sure from a business/legal sense why you wouldn’t need these  
> to be persistent attributes, however)

Agreed on all counts. Booleans are cheap, and you probably want to  
store something that proves acceptance.

> dwh

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 3:43pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/4 "2009-11-05T15:43:33Z")

</div>

You would need to add an attr\_accessor and validates\_presence\_of in  
your model…

class Model \< ActiveRecord::Base

attr\_accessor :field\_to\_validate  
validates\_presence\_of :field\_to\_validate

end

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 3:46pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/5 "2009-11-05T15:46:28Z")

</div>

Ha, should have refreshed before I submitted my answer.

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 4:59pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/6 "2009-11-05T16:59:02Z")

</div>

Thank you all for your replies.

I agree that Booleans are cheap in terms of storage but I not really  
want to keep adding database columns through the model as the number  
of questions vary over time and I do not really want to go through all  
of the hassle of a child table to hold them. I’m thinking of having  
one (persistent) attribute on the model which is a serialized hash of  
the questions and the answers. Any thoughts. Am I just being lazy?

O.

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 5:24pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/7 "2009-11-05T17:24:12Z")

</div>

As long as you don’t need to query on those values (“send email to all  
users who haven’t yet agreed to the latest T&Cs”), the serialization  
approach will work.

(and with accepts\_nested\_attributes\_for and fields\_for, how much work is  
a child table, really? 😉 )

dwh

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 5:45pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/8 "2009-11-05T17:45:16Z")

</div>

Use validates\_acceptance\_of

See

> <https://stackoverflow.com/questions/445293/ruby-on-rails-confirmation-page-for-activerecord-object-creation>

Euwyn

---

<div class="post-metadata">

**Author:** ![icke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@icke](https://www.ruby-forum.com/u/icke)\
**Post date:** [November 5, 2009, 6:47pm UTC](https://www.ruby-forum.com/t/confirmation-checkboxes-any-good-ideas/178496/9 "2009-11-05T18:47:55Z")

</div>

Denis H. wrote:

> As long as you don’t need to query on those values (“send email to all  
> users who haven’t yet agreed to the latest T&Cs”), the serialization  
> approach will work.

It will work, but it’s smelly in DB terms.

> (and with accepts\_nested\_attributes\_for and fields\_for, how much work is  
> a child table, really? 😉 )

And with proper use of migrations, how much work is adding columns,  
really?

> dwh

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
