Rails debug with passenger

Edit 2012-07-05: You can now install rack-debug in a much more easy way by using my debugger-rails gem.

Without Passenger

In my last post we learned how to debug ruby scripts. It can be done as well with a rails application, you just have to start it with script/server -u. The -u means to start on debug mode. Just make sure you have the ruby-debug gem installed.

With Passenger

That works amazing... unless you use Passenger on development. If you do, then you'll need a different way to run the debugger. Don't panic, it's quite easy, thanks to the rack-debug gem. Rack::Debug is a gem which provides an easy interface to ruby-debug for applications running on Passenger. And the good thing about it is that... it just works!

To use it, just add the ruby-debug gem to your Gemfile, make sure to use the 1.4.x version if you're running ruby 1.8.x, since the new 2.x version is prepared for ruby 1.9.2.

Now that your gem is installed, add the middleware to Rails.

And the helper rake tasks.

Now you can just add a debugger statement on any line on your application, restart it and run rake debug so that the Rack::Debug gem connects to the debugger. Easy, eh?

Enjoy the debugging!

comments powered by Disqus