Which approach would you recommend to the following issue: My app needs to have an account with several users inputting tasks on t开发者_如何转开发he 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.
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
精彩评论