如何从Visual Studio Code运行和调试Ruby on Rails? [英] How do you run and debug Ruby on Rails from Visual Studio Code?

查看:900
本文介绍了如何从Visual Studio Code运行和调试Ruby on Rails?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 如何使用内置的Visual Studio代码启动/调试功能启动Ruby on Rails?

  • How can you launch Ruby on Rails using the built-in Visual Studio Code Launch/Debug features?

如何解决Debugger terminal error: Process failed: spawn rdebug-ide ENOENT错误?

推荐答案

设置和启动

  1. 安装 VS Code Ruby插件 (点击 + + P 并在提示符下键入ext install,然后搜索ruby)
  2. 安装一些必需的Ruby gems
  1. Install the VS Code Ruby plugin (hit ++P and type ext install in the prompt, then search for ruby)
  2. Install some required Ruby gems

gem install ruby-debug-ide
gem install debase

  1. 在Visual Studio代码中添加启动配置. (如下所示的示例配置)
  1. Add a launch configuration in Visual Studio Code (example configuration shown below)

{
    "name": "Rails server",
    "type": "Ruby",
    "request": "launch",
    "cwd": "${workspaceRoot}",
    "program": "${workspaceRoot}/bin/rails",
    "env": {
        "PATH": "YOUR_PATH_HERE",
        "GEM_HOME": "YOUR_GEM_HOME_HERE",
        "GEM_PATH": "YOUR_GEM_PATH_HERE",
        "RUBY_VERSION": "YOUR_RUBY_VERSION_HERE"
    },
    "args": [
        "server"
    ]
}

在某些情况下,您可能不需要指定env部分. 在其他情况下,您可以使用CLI启动VS Code (在终端上),它在某些系统上会自动设置正确的环境变量.

In some cases you might not need to specify the env section. In other cases you can launch VS Code using the CLI (i.e. from the terminal), which on some systems automatically sets the correct environment variables.

  1. 运行!


问题排查

如果出现以下错误


Troubleshooting

If you get the following error

Debugger terminal error: Process failed: spawn rdebug-ide ENOENT

您的环境变量(env)很可能未设置,并且插件找不到所需的二进制文件.

Your environment variables (env) are most likely not set and the plugin cannot find the necessary binaries.

  1. 确保已安装所有gem,如果使用捆绑程序,请尝试运行bundler install --binstubs.
  2. 确保在启动配置中设置了env部分.运行以下shell命令以生成您的env:
  1. Make sure all gems are installed and try running bundler install --binstubs if you use bundler.
  2. Make sure the env section is set in your launch configuration. Run the following shell command to generate your env:

printf "\n\"env\": {\n  \"PATH\": \"$PATH\",\n  \"GEM_HOME\": \"$GEM_HOME\",\n  \"GEM_PATH\": \"$GEM_PATH\",\n  \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"


Windows

请确保使用path变量的正确拼写(和大小写),即Windows上的Path


Windows

Make sure to use the correct spelling (and capitalization) of the path variable, i.e. Path on Windows

这篇关于如何从Visual Studio Code运行和调试Ruby on Rails?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆