I mostly work with developers who prefer Vim or Emacs as their editor of choice. This is certainly understandable, because each of those editors provides so many ways to extend functionality and allows developers to be extremely productive in whichever way suits them best. This is especially true when working with Ruby and Rails.
For me, one downside to using Vim, though, is that I really enjoy being able to use the debuggers that are part and parcel of IDEs. True enough, there are really good gems like Pry that provide debugging functionality. But I mostly used Eclipse and IntelliJ during much of my formative programming years, and I rather enjoy a good IDE. I consider RubyMine a good IDE, and based on my experience with Ruby on Rails teams, I can't help but feel like RubyMine and its debugger is an under-utilized jewel.
Perhaps a strong contributor to part of the under-utilization, even for those who have already chosen to use RubyMine, is the fact that remote debugging can be tricky to set up and get working correctly. I've seen quite a few different Ruby on Rails projects, and every single one of them has had significantly different server configurations. My first stab at getting the remote debugger working was wrought with confusion, frustration, and, well, there would have been some hair pulling if I had any. The following are the steps I took to get remote debugging working successfully on a project that used Vagrant and Packer. Hopefully these steps help you out if you find yourself in a similar situation.
On to the good stuff!
Configuring RubyMine for Remote Debugging via Vagrant
The following steps were completed in RubyMine 8.0.4.
1. Create Deployment Configuration
Tools → Deployment → Configuration
Connection Tab
-
Click the
+
to add a server and give it a name of your choice -
Type:
SFTP
-
SFTP Host:
127.0.0.1
-
Port:
2222
-
Root Path:
/home/patmetheny
(The root path on the server) -
User name:
patmetheny
(Should be the same as the config.ssh.username) -
Password:
orchestrion
(Should be the same as the config.ssh.password) -
Web Server Root Url:
http://127.0.0.1
- Make sure to test your settings
- No, those are not real credentials. I just really, really enjoy Pat Metheny's music
Mapping Tab
-
Local path:
local/path/to/project
- Deployment path: I've left this blank before. If you get an error, this should point to the root of the project on the server
-
Web path on server:
/
2. Add a New Remote
RubyMine → Preferences → Ruby SDK and Gems
-
Click the
+
and selectNew Remote
-
Select Deployment Configuration radio button and select the server you just created
-
When you click OK to add the server, it will likely take a LONG time. It's important that you let the ENTIRE process complete.
-
After the process completes, click the new remote in the left pane to highlight it. Then, in the right pane, scroll down to make sure you see the Rails gem listed.
3. Create Run/Debug Configuration
Run → Edit Configurations
-
Click the
+
and add a new Rails Configuration -
Server:
default
-
IP address:
0.0.0.0
-
Port:
3000
-
Environment:
development
- (optional) Run Browser: This is the URL that you use to access your application via the browser.
- Use Other SDK: Select the new Remote that you created in the previous step
When you click Apply/Ok
, you should not see any errors as long as you entered the correct Ruby Interpreter Path and did not encounter any errors when adding the new Ruby SDK and Gems.
4. Start Vagrant SSH Session
Tools → Start SSH Session
Make sure your Vagrant box is already up.
5. Start the Rails Server in Debug Mode
Run → Debug
Select the configuration that you created in step 3.
As long as the the server starts up, you should be able to set breakpoints to your hearts' content!
Closing
As mentioned earlier, Ruby on Rails projects can have vastly different server configurations. If you are still experiencing issues after following these steps, feel free to Tweet at me or send a direct message. Happy debugging!