# Radio box validation

**URL:** <https://www.ruby-forum.com/t/radio-box-validation/192526>\
**Category:** Rails\
**Created:** [August 1, 2010, 12:10pm UTC](https://www.ruby-forum.com/t/radio-box-validation/192526 "2010-08-01T12:10:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![disruptivetechnolog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@disruptivetechnolog](https://www.ruby-forum.com/u/disruptivetechnolog)\
**Post date:** [August 1, 2010, 12:10pm UTC](https://www.ruby-forum.com/t/radio-box-validation/192526/1 "2010-08-01T12:10:09Z")

</div>

I have created some radio boxes as follows:

\<% f.radio\_button :usertype, “false” %\>False  
\<% f.radio\_button :usertype, “true” %\>True

where usertpe is a boolean in the db

I want to be able to create a default selection and I want to validate  
the options and ensure that for whatever reason there is always a check  
in one of the boxes…now I know a proper radio box config will always  
have one option selected. How do I validate? For example  
validates\_prescence\_of: usertype?

---

<div class="post-metadata">

**Author:** ![disruptivetechnolog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@disruptivetechnolog](https://www.ruby-forum.com/u/disruptivetechnolog)\
**Post date:** [August 2, 2010, 11:12am UTC](https://www.ruby-forum.com/t/radio-box-validation/192526/2 "2010-08-02T11:12:54Z")

</div>

Dis T. wrote:

> I have created some radio boxes as follows:
> 
> \<% f.radio\_button :usertype, “false” %\>False  
> \<% f.radio\_button :usertype, “true” %\>True
> 
> where usertpe is a boolean in the db
> 
> I want to be able to create a default selection and I want to validate  
> the options and ensure that for whatever reason there is always a check  
> in one of the boxes…now I know a proper radio box config will always  
> have one option selected. How do I validate? For example  
> validates\_prescence\_of: usertype?

Any ideas how to do this?

---

<div class="post-metadata">

**Author:** ![disruptivetechnolog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ce7236/32.png) [@disruptivetechnolog](https://www.ruby-forum.com/u/disruptivetechnolog)\
**Post date:** [August 2, 2010, 4:52pm UTC](https://www.ruby-forum.com/t/radio-box-validation/192526/3 "2010-08-02T16:52:51Z")

</div>

On Sun, Aug 1, 2010 at 06:10, Dis T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have created some radio boxes as follows:
> 
> \<% f.radio\_button :usertype, “false” %\>False  
> \<% f.radio\_button :usertype, “true” %\>True

Why not use a checkbox? Then you can be sure it’s either checked or  
unchecked.

Or is this just an example, and there are really more than two values?  
In that case, you could specify one of them as checked from the  
start.

-Dave

–  
Specialization is for insects. -RAH | Have Pun, Will Babble! -me  
Programming Blog: [http://codosaur.us](http://codosaur.us) | Work: [http://davearonson.com](http://davearonson.com)  
Leadership Blog: [http://dare2xl.com](http://dare2xl.com) | Play: [http://davearonson.net](http://davearonson.net)

- 
  - 
    - 
      - 
        - WATCH THIS SPACE \* \* \* \* \* | Ruby: [http://mars.groupsite.com](http://mars.groupsite.com)
