如何让ruby-debug-ide正常工作?

4

我无法使我的ruby-debug-ide正常工作。我有一个基本的rails应用程序,我想在RubyMine中进行调试。在我开始使用RubyMine之前,我需要在我的vagrant虚拟机中启用rdebug-ide。当我导航到我的项目目录时,我在网上阅读到需要输入以下命令:

rdebug-ide --port 1236 --dispatcher-port 26166 --host 0.0.0.0 - bin/rails s -b 0.0.0.0

然而当我运行这个命令时,我得到了这个消息:enter image description here 我还尝试了上面命令的一个修改版:(多了一个破折号)
rdebug-ide --port 1236 --dispatcher-port 26166 --host 0.0.0.0 -- bin/rails s -b 0.0.0.0

我得到的结果如下: 在此输入图片描述 这看起来很好,但是服务器从未启动。它从未显示服务器信息,并且只是停留在这里,直到我使用CTRL + C退出服务器。我无法让rdebug-ide与rails一起工作。有人知道我该如何解决这个问题吗?

你在Vagrant配置中使用固定IP地址吗?如果没有,请确保转发你正在使用的端口(1236),这样主机才能监听该端口。 - Frederic Henri
4个回答

5
我已经成功实现了RubyMine远程调试 :-)
在开始之前,请确保您已安装debase和rdebug-ide:
gem list | grep debase    
gem list | grep ruby-debug-ide

sudo gem install debase
sudo gem install ruby-debug-ide

1. 启动Rails服务器

首先,您需要启动Rails服务器:

hello_rails$ rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails server
Fast Debugger (ruby-debug-ide 0.6.0, debase 0.2.2.beta10, file filtering is supported) listens on 0.0.0.0:1234

供参考,我的Ruby、Rails和Ubuntu版本如下:

$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux-gnu]

$ rails -v
Rails 5.1.4

$ lsb_release -a
Description:    Ubuntu 16.04.3 LTS
Codename:       xenial

你可能已经注意到,服务器似乎从未启动。它只是挂在那里。这实际上是正确的。它挂在那里,等待连接,例如来自RubyMine的连接。
2. 从RubyMine进行远程调试
现在启动RubyMine(我正在使用RubyMine 2017.2.4),运行-> 调试...-> 编辑配置...
点击加号 '+' 添加新配置,并选择Ruby远程调试。

enter image description here

填写表格并点击调试按钮。服务器立即不再挂起,Rails 服务器开始启动:

hello_rails$ rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails server
Fast Debugger (ruby-debug-ide 0.6.0, debase 0.2.2.beta10, file filtering is supported) listens on 0.0.0.0:1234
WARN: Unresolved specs during Gem::Specification.reset:
      rake (>= 0.8.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
=> Booting Puma
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000

最后,您可以在RubyMine中设置断点,并开始远程调试 :-)

我已经搜索了几个小时了。虽然还没有完全解决,但现在我已经找到了正确的方向。Ubuntu 16.x / Aptana Studio。 - Chris Mendla
谢谢你,你帮助我解决了一个长期存在的问题。在RubyMine中,一次只能调试一个Docker容器(问题在于我们只能在“Ruby远程调试”自定义配置下覆盖默认端口1234:1234和26166:26168,但不能在“Rails”自定义配置下覆盖)。请参见:https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000788390-Multiple-debugger-processes-with-docker-compose - Zack Morris
我正在尝试在Linux WSL 2子系统上使其工作。它目前在IDE中挂起。因此,我正在尝试在没有IDE的情况下运行它。当您单独运行rdebug-ide bin/start等命令时,应用程序是否会启动?即,您是否可以执行基本的curl http://localhost:3000命令? - Robbo_UK

2

0
在我的情况下,我不得不用相对路径替换-- bin/rails-- ../../../../../usr/local/bin/rails,因为一旦我按下CTRL+c,就会看到消息说明找不到/usr/src/app/bin/rails

0

我认为你应该在RubyMine中的Ruby远程调试配置中添加命令。

运行 > 编辑配置 > 添加Ruby远程调试 配置。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接