我可以通过种子文件创建微型帖子并显示它们,但当我实际尝试通过该站点创建新帖子时,使用Pundit时会出现授权错误。我得到的错误是:
Pundit::AuthorizationNotPerformedError in MicropostsController#create 我的Microposts控制器看起来像这样:
class MicropostsController < ApplicationController
before_action :authenticate_user!
after_action :verify_authorized
def create
@micropost = current_user.microposts.build(micropost_params)
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to current_user
else
@feed_items = []
flash[:danger] = "Unable to create micropost!"
end
end
def destroy
end
private
def micropost_params
params.require(:micropost).permit(:content)
end
end我在想,没有为“create”操作正确设置授权,但我不确定应该如何设置它。我没有针对Micropost的评论员的政策。我试着添加一个简单的,但它没有改变任何东西。我正在学着把这些拼凑在一起,有人能给我指个方向吗?
发布于 2017-03-09 21:36:06
有一个after action filter verify_authorized,由于这个原因,您会收到此错误。如果您已经为create操作创建了策略,则使用该策略来消除错误。
https://stackoverflow.com/questions/35604475
复制相似问题