How to best handle a hierarchy

Hi all,

First of all, as this is my first post, please accept my appologies if I
have posted this to the wrong place. Any help, advice or guidance is
always gratefully received :slight_smile:

I’m pretty new to Ruby and Ruby on Rails - in fact I only picked up the
books a couple of days ago and already I’m thinking of porting some of
my apps across!

At present I’m working on a relatively simple application that does
online testing for schools and colleges. The school can create a
hierarchy using the “act_as_tree” functionality in Rails. They can also
create “Exams” and “Students”. These can be “linked” to any part of the
tree, the idea being that an Exam is visible to any students at the same
level or below it in the tree and that Students can only see exams that
are either at the same level or above them in the tree. This gives the
School great flexibility in how they can assign people to Exams.

The problem I’m facing is how to efficiently use this tree. For example
when a Student logs in, I want to be able to show them all the Exams
they can take - which involves looking at the tree to see which exams
are higher or equal to their own placement in the tree. As I’m not a SQL
or Rails expert, I’m not sure how best to do this search. Can anyone
make any recommendations?

The second problem is how to give people access to manage the tree. I’ve
decided to use a very simple approach of anyone who is listed as an
owner of a branch on the tree, can add branches to that or any branch
lower than them on the tree, and can give ownership or “admin” access to
anyone else to branches lower than the one they are linked on. This
could mean that several staff have access to several branches. The
problem is to work out who can do what to what and how to do that
efficiently.

Off the top of my head, I can do this all with lots of SQL queries etc
but I thought it would be a good idea to check with the community first
in case Rails can handle this for me or that there is a better solution
that I have overlooked.

Lastly, I appreciate you taking the time to read this post. I’ve only
been using Rails for a few days but I’m hooked already. I’d just like to
thank the people who have worked or are working on Rails for a job well
done!

Thanks in advance!

Pete