我已经成功实现了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远程调试。
填写表格并点击调试按钮。服务器立即不再挂起,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中设置断点,并开始远程调试 :-)