Forum: Ruby on Rails user defined types and validating them

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-06-13 03:37
(Received via mailing list)
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
MichaelLatta (Guest)
on 2007-06-13 03:49
(Received via mailing list)
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
This topic is locked and can not be replied to.