2012-09-13 89 views
42

我在rails中使用rack mini profiler很好,但是在一些編程會話期間,特別是我正在處理很多不同的客戶端代碼時,它會阻礙它。 (主要是在我的客戶端調試工具網絡圖等等)如何暫時禁用Rack-Mini-Profiler?

我試圖用一個之前的過濾器關閉它,也用來查看用戶是否有權查看配置文件,但「取消授權「似乎沒有爲我做任何事情。這裏是我的代碼稱爲一個過濾器之前:

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 

我也知道有一個設置「機架:: MiniProfiler.config.authorization_mode」,但我無法對可能的設置有什麼發現文檔,並沒有看到它在代碼中使用?現在它告訴我:allow_all,但是:allow_none也不會做任何事情。

即使我可以暫時在dev環境文件中設置一個值並重新啓動服務器,那也可以達到我的目的。

回答

78

獲取最新類型:

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) 
+0

優秀!謝謝你補充說,山姆! –

+0

工程太棒了!再次感謝。 –

+0

@DaveSanders不用擔心,隨時在http://community.miniprofiler.com上提出任何功能請求等。 –

21

你也可以使用Alt+p來切換。

+0

特別有用,當使用'start_hidden'選項時! – Eero

2

如果你想探查最初將被禁用,然後激活需求......像一個初始化文件中添加一個委託經回調:

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

然後在您的應用程序控制器,添加的before_filter看起來爲PP PARAM

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 =啓用到您的網址。然後你可以稍後再禁用(pp =禁用只會在當前會話中關閉它,但將ENV變量設置爲off將完全關閉,直到強制重啓爲止)。