Authentication for 2 models

I've got 2 models: School and Student

I'm using restful authentication for school so when someone signs up
they are routed to schools/new
The schools table has info for an admin, but I also need
authentication for students. Here is what I was thinking would be the
best way to do this:

#1 Combine admin and students into User model and have an admin?
boolean column. So schools would be info about the school, with no
admin info.

#2 When logging in, if the user is a student they would check the
student checkbox so the query can be against students, rather than
schools. I believe this is basically like having 2 authentication
systems which seems kind of complicated.

Which way would you guys do this?

Here’s an approach I’ve used before… you have a user model and a role model and then you link the two.

class Role < ActiveRecord::Base
has_and_belongs_to_many :users

class User < ActiveRecord::Base

has_and_belongs_to_many :roles

def has_role(role)
self.roles.detect(|r| == role}

def is_student?


def is_admin?


Role.create :name=>“admin”
Role.create :name=>“student”

user = User.create :last_name=>“Simpson”, :first_name=>“Homer”, :password=>“1234”, :password_confirmation=>“1234”, :email=>"", :login=>“homer”

user.roles << Role.find_by_name “admin”
user.roles << Role.find_by_name “student”

Makes it really easy then, cos in your views, if you use restful_auth or acts_as_authenticated, your current_user will have a .is_admin? on it.

<% if current_user.is_admin? %>
… show stuff for admins

<% end %>

Hope that helps.


I'll give this a try, thanks a lot!