views:

74

answers:

1

Which approach would you recommend to the following issue: My app needs to have an account with several users inputting tasks on the same account. Only one of the users (the one that opened the account) will have admin privileges.

I'm thinking on using Authlogic for authentication and CanCan for determining user privileges. The point is that I'd like the User that opened the Account to be admin by default being him the only one to be able to generate other Users for his account with a different privileges.

A: 

Why don't you separate your User model into Account and Profile? "Account" will have username and password for each user, and "Profile" will keep a list (via a joint table or a :through table) to keep track of the admins and the editors?

class Account < ActiveRecord::Base
  has_many :roles
  has_many :profiles, :through => :roles
end


class Profile < ActiveRecord::Base
  has_many :roles
  has_many :accounts, :through => :roles
end

class Role < ActiveRecord::Base
  belongs_to :account
  belongs_to :profile
  attr_accessible :is_admin, :account_id, :profile_id
end
porkeypop