簡體   English   中英

Rails:如何使用rolify創建角色組

[英]Rails: How to make role groups using rolify

我是新來的。 我試圖與Cancancan一起使用。
現在,如果要授予用戶創建和更新的權限,則需要兩次add_role。

user.add_role :moderator, Forum
user.add_role :creator, Forum

這里的問題是一個角色只能擁有一個權限,我想添加這樣的角色user.add_role :creator,moderator, Forum

如果這不可能,我想建立一個角色組,一個用戶可以有多個角色組,一個角色組可以有多個角色

Rolify只是創建角色。 但是要為他們分配能力或能力,例如創造力或適度性,您可以使用康康寶石。 康康中有一個名為能力的文件。 您可以在其中向不同角色分配能力。 我在下面給出一個例子。

if user.has_role? :moderator
      can :manage, [
          News,
          Event,
          Headline,
          Blog,
          Testimonial,
          CourseList,
          Chat,
          ComplaintType,
          Complaint,
          Download,
          Faculty,
          Gallery,
          Headline,
          Infrastructure,
          Leed,
          Notice,
          Press,
          Profile,
          Query,
          User,
          Newspaper
      ]
    end

    can :read, [
        Blog,
        Download,
        Event,
        Faculty,
        Gallery,
        Headline,
        Infrastructure,
        Press,
        Testimonial,
        CourseList
    ]
    can :create, [
        Leed,
        Query
    ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM