2013-05-08 20 views
0

我在使用cancan進行身份驗證的設計中使用了我的rails應用程序,我希望能夠阻止某些帳戶並阻止用戶使用被阻止的電子郵件和電話註冊。我只是不確定這是什麼最好的方法。爲rails應用程序實現禁止系統的最佳方式

我的角色:管理員,版主,以及用戶 管理員:必須有能力禁止/塊版主,和用戶 主持人:必須有能力禁止/塊用戶

我首先想到的是添加新'阻止'角色,但我認爲有更好的辦法。

回答

2

我會去最簡單的方法:只是得到一個布爾「阻止」您的用戶表。然後定義如下:

class User 
    def block(other_user) 
    if(can_block? other_user) 
     other_user.block = true 
     other_user.save! 
    end 
    end 

    def can_block?(other_user) 
    # Your logic using the roles. 
    end 
end 

直截了當,但我喜歡這種方式。

相關問題