- Add to your Gemfile and
bundle install --binstubs
(then runrails app:update:bin
to fix bundler overwriting Rails 5 default bin stub).
group :development do
gem 'ruby-debug-ide'
gem 'debase'
# If you want some nice documentation,
# refactoring support, etc too:
gem 'solargraph', require: false
gem 'rdoc', require: false
end
- Run:
$ solargraph config
Configuration file initialized.
$ solargraph bundle
-
Add the Solargraph extension to VS Code (it may be part of the Ruby or Rails extension bundles).
-
Open VS Code's settings, then click the button in the top right (looks like a document with an arrow - tooltip about editing JSON) and add the following line:
"solargraph.commandPath": "/Users/andy/.rbenv/shims/solargraph"
- Edit your
.solargraph.yml
config and change therequire: []
line to be (from castwide/solargraph#87):
require:
- actioncable
- actionmailer
- actionpack
- actionview
- activejob
- activemodel
- activerecord
- activestorage
- activesupport
-
Go to the debug section of VS Code (Cmd+Shift+D or click it in the left bar), then the little cog to configure how to run the debug server.
-
In the
launch.json
that is now opened, paste:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"useBundler": true,
"pathToRDebugIDE": "${workspaceRoot}/bin/rdebug-ide",
"program": "${workspaceRoot}/bin/rails",
"args": [
"server",
"-p",
"3000"
]
},
]
}
- Now you can set breakpoints in your code, go to the Debug tab in VS Code and click the play button alongside
Debug Rails server
, hit the pages in your browser then debug like a normal IDE.