Search code examples
ruby-on-railsrack

Rails environment variables with Rack-Mini-Profiler


I'm trying to understand how the Rails 'rack-mini-profiler' actually dumps out environment variables when you append the ?pp=env on the base URL of a request. Right now my Gemfile has the gem 'dotenv-rails configured and I'm using .env.local to populate some test variables. My question is, where is the rack-mini-profiler getting the environment variables from? There are many different ways to populate env variables within a rails app, dotenv being one of them. I've been perusing the source code of rack-mini-profiler and can't seem to find it. I see the dump_env function in 'profiler.rb' but I can't see where or how these environment variables are getting pulled from within the code. It is only showing the printing of them by using a do loop of key/value pairs. Here is the example application I'm playing with and you can see the environment variables at this URL: https://preprod.rtcfingroup.com/?pp=env Appreciate any insight. Really trying to understand this at a low level.


Solution

  • Miniprofiler does not actually have do anything since Ruby exposes the environmental variables through the ENV constant which is a hash like class.

    dump_env just iterates over them:

    body << "\n\nEnvironment\n---------------\n"
    ENV.each do |k, v|
      body << "#{k}: #{v}\n"
    end