views:

177

answers:

2

Hi everyone!

This is my first post on Stack Overflow. I am trying to build a system that authenticates three types of user with completely different site experiences: Customers, Employers, and Vendors.

I'm thinking of using a polymorphic 'User' table (using AuthLogic) with username, password, and user_type (+ AuthLogic's other required fields). If this is a good way to go, how do I set this up so after authenticating an user_id with a user_type the standard way, I can direct the user to the page that's right for them?

Thanks.

+1  A: 

I'd consider STI in this case. Then each can authenticate as a normal user, but easily branch into their own specific behavior when needed. You may need to do some work with your routes to make everything line up, however.

x1a4
Thanks very much. Can you give me some detail on how the routes would work?
sscirrus
Just setting up STI, it's going to assume that each type of user is a completely different type of resource, with its own controller and everything, so if don't want that (e.g. you want to use the users controller for all user types), you would do something like: map.resources :customers, :employers, :vendors, :controller => :users
x1a4
A: 

sscirrus, are there any relationships between them (Customers, Employers, and Vendors) at all? I've got a similar case but with a one-to-many relationship.

Sergiomb
Hi Sergio,Yes, there are relationships between all these tables, as follows (I'll only give the one half, obviously the other direction of these relationships are specified in the models): Employer has_many :vendors, Employer has_many :projects, Project has_many :customers, :through => :matching.
sscirrus