Rails:Pundit::AuthorizationNotPerformedError [英] Rails: Pundit::AuthorizationNotPerformedError
问题描述
我尝试安装 Pundit.但是当我设置 gem 时,我收到了这条消息.
I try install pundit. But when I set up the gem I have this message.
我真的不明白.我是 user.admin 也许有冲突?谢谢你的回答.
I don't really understand. I am user.admin maybe is there a conflict? Thank you for your answer.
推荐答案
Pundit 向您的控制器添加了一个名为 verify_authorized
的方法,以确保 authorize
方法在您的控制器操作.您可能设置了一个 after_action
调用 verify_authorized
(https://github.com/elabs/pundit#ensuring-policies-and-scopes-are-used).确保通过控制器操作在每个可能的执行路径中调用 authorize
.
Pundit adds a method to your controller called verify_authorized
that ensures that the authorize
method is called somewhere in your controller action. You likely setup an after_action
that calls verify_authorized
(https://github.com/elabs/pundit#ensuring-policies-and-scopes-are-used). Make sure you're calling authorize
in each possible execution path through your controller action.
或者,如果您不想授权该特定操作,您可以跳过它:
Alternatively, if you do not want to authorize that particular action, you can skip it:
class PagesControler < ApplicationController
include Pundit
after_action :verify_authorized, except: [:home]
...
end
或者如果您在继承的控制器中设置 after_action
:
or if you setup the after_action
in an inherited controller:
class ApplicationController < ActionController::Base
include Pundit
after_action :verify_authorized
...
end
class PagesControler < ApplicationController
skip_after_action :verify_authorized, only: [:home]
...
end
这篇关于Rails:Pundit::AuthorizationNotPerformedError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!