8

我正在尝试在我的 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

但是,任何用户的每个请求都会显示分析器。

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

4

1 回答 1

18

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

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

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

否则配置设置为:allowall

于 2013-04-09T08:47:34.727 回答