Search code examples
ruby-on-railsrubydebuggingrubyminepuma

Rubymine: debugging using installed Puma-dev?


Is it possbile to have Rubymine connect to (and restart) an installed/running instance of Puma-dev for the debugging session?

I use Puma-dev to test my Rails app on "Appname".test, yet if I need to debug something in the app and want to use Rubymine's built-in debugger, I can only let it start an additional instance of Puma on Port 3000 (or whatever Port I choose) but not the already running Puma-dev on port 80/443.

Is it at all possible?


Solution

  • This is possible with remote debugging. To configure, you have to make some changes to your app:

    1. Add export RUBY_DEBUG_PORT=1234 to .env or .powenv or any file puma-dev will load an environment variable from. Feel free to use whatever port you'd like, although RubyMine uses 1234 by default.

    2. Add the ruby-debug-ide and debase gems to your project's Gemfile.

    3. Add an initializer to your project to initialize remote debugging, like so:

      if Rails.env.development? && ENV['RUBY_DEBUG_PORT']
        Debugger.start_server nil, ENV['RUBY_DEBUG_PORT'].to_i
      end
      
    4. Restart puma-dev.
    5. Go to Edit Configurations in RubyMine and add a "Ruby remote debug" config. Name it whatever you'd like. Change the port to the port you set via RUBY_DEBUG_PORT. Set your local and remote root folders to your project root.
    6. Select your newly created configuration and click the Debug button. It should connect to the debugger running in your puma-dev process.