2013-05-08 51 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 

直截了当,但我喜欢这种方式。

相关问题