如何限制用户访问权限,以便用户只能阅读自己的记录?
我试过了:
def初始化(用户) 可以:读取,用户,:id =>用户身份还有这个:
def初始化(用户) 可以:阅读,用户…
:read != :show :read == [:show, :index]
不幸的是,我没有设置测试它所以它在黑暗中拍摄。
can :show, User, :id => user.id
似乎放
authorize! :show, @user
在节目动作和
@users = User.accessible_by(current_ability)
在索引操作中使用以下方法解决了我的问题:
def initialize(user) can :read, User, :id => user.id
我现在可以看到我应该使用load_and_authorize_resource而不仅仅是authorize_resource,因为它会自动添加那些。