我正在使用Rails 4的设计和CanCan。两者都工作得很好,但我不想对控制器的2个特定动作有效。所以我对设计做了如下操作:
before_filter :authenticate_user!, except: [:check_in_list, :check_in]
这要求用户登录除 check_in_list
和check_in
操作之外的所有例外。完全如我所愿。问题是当我添加authorize_resource
时:
before_filter :authenticate_user!, except: [:check_in_list, :check_in]
authorize_resource
现在,如果我试图去check_in_list
或check_in
页面,它重定向我登录。是否有类似于authorize_resource
的except
选项?
根据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]