views:

64

answers:

2

I'm creating a Rails app for students and high schools and I'm having some trouble with my User.rb.

I want to have a user model to be used for logging in, but having that user have many roles. The tricky part is that I want users that have a student role to have_one student page, and those that have a role of principal to have_one high_school page.

The students and also nested in the high_school so the entire thing becomes a big mess.

So my question(s): How do I limit a user to only creating one student / high school to represent them? Also how would I nest this student pages inside the highschool without screwing up the user system?

My environment: Rails3 and Ruby 1.9.2dev

Thank you!

Follow up: Would it be possible to put the name of the high_school in the subdomain? That would make the url look like

highschoolname.mysite.com/students/eric-koslow

+1  A: 

I'd suggest polymorphic association to user_representations. It'd hold info about which high_school object or which student_page to associate the appropriate user to.

Eimantas
A: 

You can made a validation to avoid the multi-creation.

shingara