轨道上的红宝石 - 使用 CanCan 进行authorize_resource,但不希望它用于所有操作



我正在使用Rails 4的设计和CanCan。两者都工作得很好,但我不想对控制器的2个特定动作有效。所以我对设计做了如下操作:

before_filter :authenticate_user!, except: [:check_in_list, :check_in]

这要求用户登录除 check_in_listcheck_in操作之外的所有例外。完全如我所愿。问题是当我添加authorize_resource时:

before_filter :authenticate_user!, except: [:check_in_list, :check_in]
authorize_resource

现在,如果我试图去check_in_listcheck_in页面,它重定向我登录。是否有类似于authorize_resourceexcept选项?

根据gem文档https://github.com/ryanb/cancan/wiki/authorizing-controller-actions,您可以使用skip_authorize_resource:

skip_authorize_resource only: [:check_in_list, :check_in]
skip_authorize_resource only: [:check_in_list, :check_in]

相关内容

最新更新