When you have several entities that are almost the same, but not quite, 
then using sub- / superclasses might be a good idea.

When a user is either a regular user or an admin, then the boolean flag 
on the user model is fine, but when you start to get several user types, 
then I think its better to make subclasses of user for each type.

Just add a new field to the user model "type" (string) and then you can 
create one model for each user type, like

class SalesPerson < User
end

Once that is done you can pretty much treat the models as if they had 
separate database tables.
If you do SalesPerson.new, then rails will automatically set the type 
field to "SalesPerson". If you do SalesPerson.find, rails will know to 
look in the users table where type is SalesPerson.

The great thing here is that you can have separate models for each user 
type, without needing a bunch of tables with all the same fields, and 
you can add logic to the user model that are inherited by all the user 
types for the logic that the they share.

One warning though:
Dont try to operate on user.type, this will create weired error 
messages.
If you ever need to access that field directly, use user['type'].
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to