gpt4 book ai didi

ruby-on-rails-4 - 在一个 Controller 上跳过专家范围

转载 作者:行者123 更新时间:2023-12-04 23:49:38 26 4
gpt4 key购买 nike

我想跳过 policy_scope Pundit 对一个 Controller (家庭)的要求。我试过这个:

 class ApplicationController < ActionController::Base
include Pundit
after_action :verify_authorized, :except => :index, unless: :devise_controller?
after_action :verify_policy_scoped, :only => :index, unless: controller.controller_name == "home"
end

class HomeController < ApplicationController
def index
redirect_to (new_user_session_path) unless user_signed_in?
if user_signed_in?
@user=current_user
end
end
end

但我认为 Controller 尚未定义或其他什么?有什么想法或建议吗?

最佳答案

我通过向家庭 Controller 添加一个 skip_after_action 来实现这一点:

class HomeController < ApplicationController
skip_after_action :verify_policy_scoped, :only => :index
end

关于ruby-on-rails-4 - 在一个 Controller 上跳过专家范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25651108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com