Topic: Categorizing users.

What would be the best way to allow different signup for different users?

For instance, we have 3 types of users: Manager, Worker, Client.

Should i just create a boolean field in the user table?

Re: Categorizing users.

If the users behave similar, but have a few differences, then I recommend considering doing Single Table Inheritence. Just put a "type" string column in your users table and then you can sublcass User with whatever you want:

class User < ActiveRecord::Base
end

class Manager < User
end

class Worker < User
end

class Client < User
end


That way you can override any methods in the subclass which need to behave differently depending on the type of user.

Railscasts - Free Ruby on Rails Screencasts

Re: Categorizing users.

otherwise... polymorphic association if each kind of user has distict different attributes.

Re: Categorizing users.

what if i just use acts_as_tree and have the following

#User.rb

class User < ActiveRecord::Base
        has_many :category_of_owner, :foreign_key => "owner_id" , :class_name => "Category"
        has_many :category_of_client, :foreign_key => "client_id", :class_name => "Category"
        has_and_belongs_to_many :category_of_worker, :foreign_key => "worker_id", :class_name => "Category", :conditions => ["usertype LIKE ?", "Worker"]
end

#Category.rb

class Category < ActiveRecord::Base
    acts_as_tree :order => "name"
   
    belongs_to :owner, :foreign_key => "owner_id", :class_name => "User"
    belongs_to :client, :foreign_key => "client_id", :class_name => "User"
    has_and_belongs_to_many :worker, :foreign_key => "worker_id", :class_name => "User", :conditions => ["usertype LIKE ?", "Worker"]
end


So three tables. Category, User, Categories_Users

in the HABTM, would rails be smart enough to find the join table on its own? or am i defining these wrong way.

Re: Categorizing users.

That way you can override any methods in the subclass which need to behave differently depending on the type of user.

This sounds like something that will be useful in my application, but I was hoping you could expand on it a bit further.  What is an example of something you would put in the subclass?

Re: Categorizing users.

I found my answer in another discussion... http://railsforum.com/viewtopic.php?pid=22104#p22104