I’m now a Ruby on Rails programmer and the past week I’ve been frantically learning how to develop on my MacBook Air.
- Mac OS X Mountain Lion
- Xcode 4.4
- Apache 2.2.22
- MySQL 5.5.27
- Phusion Passenger 3.0.15
- Ruby 1.8.7
- Rails 2.3.12
I wanted an IDE like Zend Studio, whose remote debugging support for PHP I simply love.
After some research I bought a license for RubyMine 4.5, because I was impressed by its integration with Ruby and Rails and its excellent debugger.
Unfortunately, RubyMine’s offers remote debugging configurations that (at the moment) don’t allow to hook into a running instance. That means that you can’t remotely debug on your own application stack, unless your Rails server is run by a command line script.
Well… luckily enough, I’ve just found another way that allows me to remotely debug using my own stack.
In fact, RubyMine’s local debugger does support Passenger Standalone as a Rails server, through a command line like this:
in conjunction with the following file (config/initializers/rubymine_passenger_debug.rb)
And it works like a charm.
This example is based on the Notebook app created in the RubyMine tutorial Discover RubyMine in a Few Simple Steps.
(1/6) Edit /etc/hosts
I make an alias in my Mac such that notebook.dev corresponds to 127.0.0.1 (localhost).
(2/6) Edit …/apache2/extra/httpd-vhosts.conf
I make a virtual host for my “remote” development site. Note that the notebook folder is under Sites. On the other hand, my “local” development site will be under RubymineProjects. To synch them you need to deploy, i.e. delete the notebook folder in Sites and copy again there the one in RubymineProjects.
(3/6) Edit …/apache2/httpd.conf
This is where Passenger is configured into Apache. I configure my instance like RubyMine does when it starts Passenger Standalone for local debugging. This is a minor drawback… I think I can live with it + remote debugging.
(4/6) Create …/notebook/lib/tasks/rdebug.rake
I create a simple rake task to start the server with debugging enabled.
(5/6) Add RubyMine – Run/Debug Configurations – Ruby remote debug
I add a new Ruby remote debug configuration. Remote host is the IP of my “remote” development site. The remote port can be any that is not already used. The local port is decided by the dialog box, so you’ll have a different number each time you add a new configuration. Remote and local root folders must match the same app tree such that the mapping works when debugging.
(6/6) Edit …/notebook/config/environments/development.rb
I add this block at the end of my development configuration. It is the keystone. Note that remote_host and remote_port must match the corresponding values in the Ruby remote debug configuration.
This is the sequence I use for remote debugging. Apart from the first step, the rest is the same used for local debugging.
- From a Terminal window: rake rdebug
- From RubyMine – (notebook) Debug
- From the browser – Reload a page and hit a breakpoint
- RubyMine gets the focus and waits for you to debug
And it works like a charm.