Multiple user roles in Ruby on Rails

Posted by aguynamedloren on Stack Overflow See other posts from Stack Overflow or by aguynamedloren
Published on 2010-12-29T04:25:33Z Indexed on 2010/12/29 5:54 UTC
Read the original article Hit count: 384

I am building an inventory management application with four different user types: admin, employee, manufacturer, transporter. I haven't started coding yet, but this is what I'm thinking.. Manufacturers and transporters are related with has_many :through many-to-many association with products as follows:

class Manufacturer < ActiveRecord::Base
 has_many :products
 has_many :transporters, :through => :products
end

class Product < ActiveRecord::Base
 belongs_to :manufacturer
 belongs_to :transporter
end

class Transporter < ActiveRecord::Base
 has_many :products
 has_many :manufacturers, :through => :products
end

All four user types will be able to login, but they will have different permissions and views, etc. I don't think I can put them in the same table (Users), however, because they will have different requirements, ie: vendors and manufacturers must have a billing address and contact info (through validations), but admins and employees should not have these fields.

If possible, I would like to have a single login screen as opposed to 4 different screens.

I'm not asking for the exact code to build this, but I'm having trouble determining the best way to make it happen. Any ideas would be greatly appreciated - thanks!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby