# User defined types and validating them

**URL:** <https://www.ruby-forum.com/t/user-defined-types-and-validating-them/106664>\
**Category:** Rails\
**Created:** [June 13, 2007, 1:37am UTC](https://www.ruby-forum.com/t/user-defined-types-and-validating-them/106664 "2007-06-13T01:37:53Z")\
**Posts on this page:** 2\
**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:** [June 13, 2007, 1:37am UTC](https://www.ruby-forum.com/t/user-defined-types-and-validating-them/106664/1 "2007-06-13T01:37:53Z")

</div>

so i have a multi-part problem that im not quite good enough to wrap  
my hands around yet. maybe someone can offer me some help.

i have a rails app that among other things, tracks orders and reviews.  
now i’m trying to add some quality-control functionality through  
inspection\_sheets…

ideally, an inspection sheet is composed of its associated order\_id,  
and (im assuming the right way to do it) has\_many inspection\_rows…  
each inspection\_row its inspection\_sheet\_id… and then multiple user  
defined fields defining what i want to inspect for each job…

each job will have a variety of things needing to be inspected and  
they’re all defined at runtime…

for example…  
a min-max field which will take two numbers, a minimum and a maximum  
passing value… if the number given is within the passing range good…  
if its not, i’ll still accept it… i just want to format it  
differently upon viewing it later… that part i dont think is so  
hard…

anyhow, another type will be boolean, which will either be a go/no-  
go… good/bad… on/off…etc… again, thats simple…

but from a design aspect… the main question is, how do i pull all of  
this together and at creation time - allow myself to choose between  
what type of field it is? do i maintain two separate tables for  
boolean values and min-max values? what about adding new types down  
the line?

alright. im fairly certain that this post is pretty drawn out as it  
is… so if anyone wants to offer any advice, i’d be happy to elaborate  
further…

thanks a bunch for your time.  
-fjm

---

<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:** [June 13, 2007, 1:49am UTC](https://www.ruby-forum.com/t/user-defined-types-and-validating-them/106664/2 "2007-06-13T01:49:54Z")

</div>

You could store all values in one table with them represented as  
strings in the database (if you do not need to search on them).

For the 2 cases you present you could use integers or floats and just  
represent boolean as 0.0 and non-0.0 since 0.0 can be represented  
reliably on any floating point format.

The table of values would have a value type ID and an order ID, or job  
ID, or trip ID depending on how detailed you want to be in tracking  
work.

Michael
