The ‘ruby-debug-ide’ gem provides the protocol to establish communication between the debugger engine (such as debase) and IDEs (for example, RubyMine, Visual Studio Code, NetBeans or Eclipse). It redirects commands from the IDE to the debugger engine. Then, it returns answers/events received from the debugger engine to the IDE.
For Ruby version 2.x, you need to install gems ruby-debug-ide and debase.
gem ‘ruby-debug-ide’, ‘0.7.3’ # An interface which glues ruby-debug to IDEs like Eclipse, NetBeans, RubyMine and Visual Studio Code.
gem ‘debase’, ‘0.2.4.1’ # Fast implementation of the standard debugger debug.rb for Ruby.
For a Rails application, run the following command:
rdebug-ide –host 0.0.0.0 –port 1234 –dispatcher-port 1234 — bin/rails s
If you want to debug a Rails application run using Docker Compose, you need to start the Rails server from the Docker in the following way:
command: bundle exec rdebug-ide –host 0.0.0.0 –port 1234 — bin/rails s -p 3000 -b 0.0.0.0
volumes:
– .:/sample_rails_app
ports:
– “1234:1234”
– “3000:3000”
– “26162:26162”
Note that all ports above should be exposed in the Dockerfile.
vendor/bundle/ruby/2.6.0/gems/ruby-debug-ide-0.7.3/bin/rdebug-ide –debug –host 127.0.0.1 –port 1234 –dispatcher-port 3010 — vendor/bundle/ruby/2.6.0/bin/unicorn -p 3010
Now open the VSCode and add the following configuration into launch.config.
{ "version": "0.2.0", "configurations": [ { "name": "Start Debugging", "type": "Ruby", "request": "attach", "remoteHost": "127.0.0.1", "remotePort": "1234", // this port will come from dispatcher port after the process started running "remoteWorkspaceRoot": "${workspaceRoot}", "cwd": "${workspaceRoot}", "showDebuggerOutput": true, } ] }
Press F5 to start debugging. VSCode client attaches to the Unicorn that is started outside the VSCode.