Skip to content

Instantly share code, notes, and snippets.

@strika
Created June 23, 2016 09:49
Show Gist options
  • Save strika/4e02430019aedcc0281d6712a052f2af to your computer and use it in GitHub Desktop.
Save strika/4e02430019aedcc0281d6712a052f2af to your computer and use it in GitHub Desktop.
How to enable Rack MiniProfiler on staging?

Add these few lines to Gemfile:

gem 'rack-mini-profiler', :require => false
gem 'flamegraph'
gem 'stackprof'
gem 'memory_profiler'

Add this to config/initializers/rack_profiler.rb

require 'rack-mini-profiler'

Rack::MiniProfilerRails.initialize!(Rails.application)
Rack::MiniProfiler.config.position = 'right'

if Rails.env.production? or Rails.env.staging?
  Rails.application.middleware.delete(Rack::MiniProfiler)
  Rails.application.middleware.insert_after(Skylight::Middleware, Rack::MiniProfiler)
end

Add this to ApplicationController:

before_action :authorize_mini_profiler

def authorize_mini_profiler
  if %w(staging edge).include?(Rails.env)
    Rack::MiniProfiler.authorize_request
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment