【问题标题】:One Account with many users authentication in rails在 Rails 中具有多个用户身份验证的一个帐户
【发布时间】:2023-09-11 23:58:01
【问题描述】:

对于以下问题,您会推荐哪种方法:我的应用需要有一个帐户,多个用户在同一个帐户上输入任务。只有其中一位用户(开户者)拥有管理员权限。

我正在考虑使用 Authlogic 进行身份验证,使用 CanCan 确定用户权限。关键是我希望打开帐户的用户默认是管理员,他是唯一能够为他的帐户生成具有不同权限的其他用户的用户。

【问题讨论】:

    标签: ruby-on-rails authentication cancan


    【解决方案1】:

    您为什么不将您的用户模型分为帐户和个人资料? “Account”将拥有每个用户的用户名和密码,“Profile”将保留一个列表(通过联合表或 :through 表)以跟踪管理员和编辑?

    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
    

    【讨论】:

      最近更新 更多