I would go with a single 'status' field.

-----Original Message-----
From: rubyonrails-talk@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
Tony Tony
Sent: Tuesday, October 21, 2008 12:59 PM
To: rubyonrails-talk@googlegroups.com
Subject: [Rails] Boolean database + Site Design/Architecture Question


Hi all,

As usual, you've all been very helpful in the past and I thank you for 
continuing to help myself and others.

Today I have the following code/database architecture question which I would 
like you guys to help me out with.


Children Table   (user has_many children)
--------------
...
is_lost boolean, default => false
is_found boolean, default => false
...


Basically, a child is "safe" if he is not flagged as lost or found (so a child 
has 3 possible states: safe, lost, found).

I created a custom validation to avoid a child from being both lost AND found 
with this:

[code]
def validate
if is_lost? and is_found?
      errors.add_to_base("A child can't be lost <i>AND</i> found at the same 
time!")
    end
end
[/code]

This all works great and validates correctly. HOWEVER, the only way I've been 
able to select if a child is lost or found is through check boxes (not the best 
way to do this). I think a drop down box would be the better solution to select 
if a child is either lost or found (or safe)


My question is this:

Is this the best way to achieve what I am trying to do? Is it better to just 
have a column in my table named "status" where the values would be either Safe, 
Lost, Found and remove the is_lost and is_found boolean columns instead?

If the current way I designed it is good, how can I create a drop down box that 
could handle both the is_lost and is_found data?


I know this is a disaster (in my eyes) but I would like the opinions and 
suggestions of you experienced folks.


Thank you!!!
-Tony


P.S.  Let me know if you need more info or code to help you understand this.
--
Posted via http://www.ruby-forum.com/.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to