Implementation of a decision tree with radio buttons

Hi all!
I have been using ruby on rails recently to create a data entry form
coupled with a database for archaelogical findings in Greece. Until now
I have managed to solve all minor problems through serching the web. I
am now stuck and I seek your expert advice ergently!

In the form of an “item”, I have a set of 6 radio buttons which work
like a decision tree. Let’s call them r1 to r6, for simplicity.
Checking r1 (from the pair of r1, r2) then either r3 or r4 pair can be
checked. If r3 is checked, then r5 or r6 pair can be checked.

However, if r4 is checked, then r5 and r6 must be both unchecked, the
same for r2.
If r2 is checked, then the user must not be allowed to check any of r3
to r6. In c for instance this could be solved in series of
“if-then-else” statements.

The pseudocode could be as follows:
if r1checked then
r3 or r4 can be checked
if r3 checked then
r5 or r6 can be checked
r2 can not be checked
else if r4 checked
r5 and r6 can not be checked
elseif r2 checked
r3, r4, r5,r6 can not be checked

The values for the 6 radio buttons are stored in the database in nested
lookup tables, ie. the values of pair (r1, r2) are in lup1 table, pair
(r3,r4) in lup2 table and (r5,r6) in lup3 table, while foreing key fk3
connects lup3 to lup2 , fk2 connects lup2 to lup1 table, and finally fk1
connects lup1 table to an “items” table, where other data of an item are

I have created a scaffold called item and models for lup1, lup2 and lup3
tables with the proper belong_to and have_one relationships.

How can I implement the restrictions I mentioned above in the form.rhtml
used to add a new item or edit it ?
I include part of the relevant code and I hope somebody can advise:

(Pattern refers to lu1 table
Scheme refers to lu2 table
Detail refers to lu3 table)

<% Pattern.find(:all).each do |p| %>
<%=><%=radio_button_tag(“item[pattern_id]”,,@item.pattern_id == %>
<% end %>
<% Scheme.find(:all).each do |s| %>
<><%=radio_button_tag(“p.scheme_id”,, p.scheme_id == %>

<% Detail.find(:all).each do |d| %>
<><%=radio_button_tag(“s.detail_id”,, s.detail_id == %>