如何临时禁用Rack-Mini-Profiler?

时间:2012-09-13 15:16:50

标签: ruby-on-rails ruby-on-rails-3 rack-mini-profiler

我在rails中使用机架迷你探测器就好了,但在某些编码会话期间,特别是在我处理许多不同的客户端代码时,它会妨碍我。 (主要在我的客户端调试工具网络图等)。

我正试图通过前置过滤器将其关闭,这也可以用来查看用户是否有权查看该配置文件,但“取消授权”似乎对我没有任何作用。这是我的代码,称为前过滤器:

def miniprofiler  
 off = true
 if off || !current_user
  Rack::MiniProfiler.deauthorize_request
  return
 elsif current_user.role_symbols.include?(:view_page_profiles)    
  Rack::MiniProfiler.authorize_request
  return
 end
 Rack::MiniProfiler.deauthorize_request
end

我也知道有一个设置“Rack :: MiniProfiler.config.authorization_mode”但是我找不到有关可能的设置的文档,而没有在代码中看到它?现在它告诉我:allow_all,但是:allow_none也没有做任何事情。

即使我可以在开发环境文件中临时设置一个值并重新启动服务器,这也符合我的目的。

3 个答案:

答案 0 :(得分:80)

获取最新信息并输入:

http://mysite.com?pp=disable

完成后输入

http://mysite.com?pp=enable

有关所有选项,请参阅?pp=help

Append the following to your query string:

  pp=help : display this screen
  pp=env : display the rack environment
  pp=skip : skip mini profiler for this request
  pp=no-backtrace : don't collect stack traces from all the SQL executed (sticky, use pp=normal-backtrace to enable)
  pp=normal-backtrace (*) : collect stack traces from all the SQL executed and filter normally
  pp=full-backtrace : enable full backtraces for SQL executed (use pp=normal-backtrace to disable) 
  pp=sample : sample stack traces and return a report isolating heavy usage (experimental works best with the stacktrace gem)
  pp=disable : disable profiling for this session 
  pp=enable : enable profiling for this session (if previously disabled)
  pp=profile-gc: perform gc profiling on this request, analyzes ObjectSpace generated by request (ruby 1.9.3 only)
  pp=profile-gc-time: perform built-in gc profiling on this request (ruby 1.9.3 only)

答案 1 :(得分:22)

您也可以使用Alt+p切换。

答案 2 :(得分:2)

如果您希望最初禁用探查器,然后按需激活...在初始化文件中添加预授权回调,如:

Rack::MiniProfiler.config.pre_authorize_cb = lambda {|env| ENV['RACK_MINI_PROFILER'] == 'on'}

然后在你的应用程序控制器中,添加一个查找pp param

的before_filter
before_filter :activate_profiler
def activate_profiler
  ENV['RACK_MINI_PROFILER'] = 'on' if params['pp']
  ENV['RACK_MINI_PROFILER'] = 'off' if params['pp'] == 'disabled'
end

您的环境最初不会设置RACK_MINI_PROFILER,但如果您想打开它,可以将?pp = enabled添加到您的网址上。然后您可以稍后再次禁用(pp =禁用将仅为当前会话关闭它,但将ENV变量设置为off将完全终止它,直到您重新打开它为止。)