加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 为什么我不能为非管理员用户取消Rack-mini-pro

发布时间:2020-12-17 04:18:37 所属栏目:百科 来源:网络整理
导读:我正在尝试在我的ROR应用程序上安装Rack-mini-profiler. 我安装了gem并且探查器在开发中运行良好,但我无法取消对非管理员用户的特定请求的授权. 我将以下代码放在我的ApplicationController before_filter中 def authorize_mini_profiler if current_user.ni
我正在尝试在我的ROR应用程序上安装Rack-mini-profiler.
我安装了gem并且探查器在开发中运行良好,但我无法取消对非管理员用户的特定请求的授权.
我将以下代码放在我的ApplicationController before_filter中
def authorize_mini_profiler
    if current_user.nil?
      Rack::MiniProfiler.deauthorize_request
      return
    elsif is_admin_user
      Rack::MiniProfiler.authorize_request
      return
    end
    Rack::MiniProfiler.deauthorize_request
end

在调试中,我看到调用了deauthorize方法,但仍然显示了探查器.

我甚至尝试过使用这段代码

def authorize_mini_profiler
    Rack::MiniProfiler.deauthorize_request
end

但是,任何用户的每个请求都会显示探查器.

有谁知道可能是什么问题?

解决方法

好吧,对于那些遇到同样问题的人……

更深入的调试发现gem配置为忽略init上的授权机制.为了仅在某些情况下启用性能分析(例如,非生产或仅对管理员用户),您需要覆盖application.rb中的默认配置(或者最好是某些特定的配置文件):

Rack::MiniProfiler.config.authorization_mode = :whitelist if Rails.env.production?

否则配置设置为:allowall

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读