Shunske
by Shunske

Categories

  • installation

rdebug-ide

How to debug for Rails application using VSCode.

  • Install ruby extention to VSCode

https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby

  • Add this code to your Gemfile and bundle install to your Rails application
group :development do
  # Debug for vscode
  gem "ruby-debug-ide"
  gem "debase"
end
  • Add config to your VSCode

Add this config to .vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Rails",
      "type": "Ruby",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "program": "${workspaceRoot}/bin/rails",
      "pathToRDebugIDE": "${workspaceRoot}/vendor/bundle/ruby/2.4.0/bin/rdebug-ide",
      "useBundler": true,
      "args": [
        "server"
      ]
    }
  ]
}

vscode

pry

  • Automatically require some gems for pry command
tail ~/.pryrc
begin
  require 'awesome_print'
  require 'tapp'
rescue LoadError
else
  AwesomePrint.pry!
end

awesome_print

  • Show params for human friendly.
❯ bundle exec pry
[1] pry(main)> h = { a:100, b:200 }}

{
    :a => 100,
    :b => 200
}

tapp

  • Useful gem for print debug. Print values in method chain.
❯ bundle exec pry
[1] pry(main)> { a:100, b:200 }.tapp.to_a.tapp.first.tapp
{:a=>100, :b=>200}
[[:a, 100], [:b, 200]]
[:a, 100]
[
    [0] :a,
    [1] 100
]
  • Sometimes I forgot print debug code using p and pp. But tapp gems prepare command for findind debug code.
bundle exec tapp grep