我正在尝试在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在debug中,我看到deauthorize方法被调用,但分析器仍然显示。
我甚至试着使用下面的代码
def authorize_mini_profiler
Rack::MiniProfiler.deauthorize_request
end但是,任何用户的每个请求都会显示分析器。
有没有人知道问题出在哪里?
发布于 2013-04-09 16:47:35
好吧,对于那些遇到同样问题的人...
更深入的调试发现,gem被配置为忽略init上的授权机制。为了仅在某些情况下启用性能分析(例如,非生产或仅供管理员用户使用),您需要覆盖application.rb中的默认配置(或者最好是某个特定的配置文件):
Rack::MiniProfiler.config.authorization_mode = :whitelist if Rails.env.production?否则,配置将设置为:allowall
https://stackoverflow.com/questions/15873939
复制相似问题