Design advice for newbie

Hello,
I have a typical class called Users. Each user has a Role (one of
administrator, teacher, student, parent, or trustee). How do I design my
controller/views/routes to best implement links to administer each
group, like this:
Student Administration
Parent Administration
Teacher Administration
Trustee Administration
Administrator Administration

Right now, each of these links activates the user_controller and lists
all users (for example the student admin link: <%= link_to "Student
Administration", :controller => 'users', :action => 'index' %>).
I would like each link to get only the users having the appropriate
role. I know I can create the link_to with an additional parameter
(e.g., role => 'teacher') which will change the route to
'/users?role=teacher', but is this the correct, RESTful, Rails way of
doing this? If not, can you please point me in the right direction or
towards some guidelines? Thanks!

···

--
Posted via http://www.ruby-forum.com/.

This question probably belongs in the Rails list/group.

In any case, I don't know your situation, but; are you sure a trustee
administer cannot also be a student administer, or a a parent
administer also be a trustee administer. Sound like a weird relation
you are trying to force. If they are mutually exclusive, fine, but
I've never seen a setup like this.

The problem is, I guess, that you may have to make the shoe fit later
if you want to go that route.

Todd

···

On Sun, Nov 9, 2008 at 5:17 PM, John Goetz <goetz.john@gmail.com> wrote:

Hello,
I have a typical class called Users. Each user has a Role (one of
administrator, teacher, student, parent, or trustee). How do I design my
controller/views/routes to best implement links to administer each
group, like this:
Student Administration
Parent Administration
Teacher Administration
Trustee Administration
Administrator Administration

John Goetz wrote:

I would like each link to get only the users having the appropriate
role. I know I can create the link_to with an additional parameter
(e.g., role => 'teacher') which will change the route to
'/users?role=teacher', but is this the correct, RESTful, Rails way of
doing this? If not, can you please point me in the right direction or
towards some guidelines? Thanks!

This sounds fine to me, but for an alternative approach you could
consider Single Table Inheritance. That is, you have separate classes
for Student, Parent, Teacher etc, but they all live in the users table,
and can all be considered as a User. Teacher.find(...) will
automatically be restricted to User.find(:conditions =>
"type='Teacher'")

http://ar.rubyonrails.com/classes/ActiveRecord/Base.html

Scroll down to "Single table inheritance" Also, the book "Agile Web
Development with Rails" has a section on this (but don't buy the 2nd
edition now, wait for the 3rd edition due in December)

However as already mentioned, this may be a Bad Idea. It's quite
possible for the same person to be both a student and a parent, or a
teacher and a trustee.

Person.has_and_belongs_to_many :roles may be a better way of modelling
this. Admittedly the SQL finders get a bit more awkward.

···

--
Posted via http://www.ruby-forum.com/\.

Todd Benson wrote:

···

On Sun, Nov 9, 2008 at 5:17 PM, John Goetz <goetz.john@gmail.com> wrote:

Hello,
I have a typical class called Users. Each user has a Role (one of
administrator, teacher, student, parent, or trustee). How do I design my
controller/views/routes to best implement links to administer each
group, like this:
Student Administration
Parent Administration
Teacher Administration
Trustee Administration
Administrator Administration

This question probably belongs in the Rails list/group.

In any case, I don't know your situation, but; are you sure a trustee
administer cannot also be a student administer, or a a parent
administer also be a trustee administer. Sound like a weird relation
you are trying to force. If they are mutually exclusive, fine, but
I've never seen a setup like this.

The problem is, I guess, that you may have to make the shoe fit later
if you want to go that route.

Todd

You are absolutely right...sorry for the 'mispost'.

I originally set these up as mutually exclusive groups, but now that you
point it out, it makes sense to find a way to sub-class User. Thanks for
your insight.

--
Posted via http://www.ruby-forum.com/\.

Brian Candler wrote:

This sounds fine to me, but for an alternative approach you could
consider Single Table Inheritance. That is, you have separate classes
for Student, Parent, Teacher etc, but they all live in the users table,
and can all be considered as a User. Teacher.find(...) will
automatically be restricted to User.find(:conditions =>
"type='Teacher'")

http://ar.rubyonrails.com/classes/ActiveRecord/Base.html

Scroll down to "Single table inheritance" Also, the book "Agile Web
Development with Rails" has a section on this (but don't buy the 2nd
edition now, wait for the 3rd edition due in December)

However as already mentioned, this may be a Bad Idea. It's quite
possible for the same person to be both a student and a parent, or a
teacher and a trustee.

Person.has_and_belongs_to_many :roles may be a better way of modelling
this. Admittedly the SQL finders get a bit more awkward.

Thanks, Brian, for the direction. With Todd's advice also, I will
investigate how to write up the has-and-belongs-to-many relationship and
single table inheritance.
I already pre-purchased the 3rd edition of Agile Development with Rails
and have a PDF of the beta release. It's helped me a lot, but I didn't
get to that section yet. Time to hit the book again!

···

--
Posted via http://www.ruby-forum.com/\.