Debugging your rails controllers with JRuby and Mongrel

Posted by Colin Fri, 24 Jul 2009 07:48:00 GMT

If like me you think that NetBeans is a superb IDE, but quiet often for some unknown reason end up firing up TextMate to fix a bug or add a new feature, only to realise you lose all of the lovely debugging tools that come with the IDE. Well we can take a step in the right direction by allowing you to break out of your controller actions and into a irb console..

First things first we need a java implementation of ruby-debug-base. Fortunately one exits at http://rubyforge.org/frs/?group_id=3085 but it is not installable remotely so download the latest version of this file into a local directory (at time of writing this was ruby-debug-base-0.10.3.1-java.gem)

Fire up terminal and go to the directory that contains the gem file and enter the following

jruby -S gem install ruby-debug-base-0.10.3.1-java.gem
we also need to install the native ruby-debug gem as mongrel requires this to run with the –debugger swtich
ruby -S gem install ruby-debug

O.K with that all installed successfully we can now go ahead and start up our mongrel instance so go to your rails app and issue the following command, to start mongrel

jruby --debug -S script/server --debugger
Now in your controllers, you can create a breakpoint by entering debugger at the point you wish. This will cause the server to break into an irb session. From here you can write any code to inspect your controller you want. Be careful though as you are just issuing ruby commands so Model.destroy_all really will destroy all :)


About

We are a small British company that produces business-oriented software and solutions. These articles are a product of our daily work - information that we think might be useful to share. We hope you find them useful.

Our Software

These are some of our products. Several are open source, some are web-based and others are proprietary:

Categories

Archives

Syndicate

ml> ._trackPageview(); } catch(err) {} ml> l> pageTracker._trackPageview(); } catch(err) {} ml> ._trackPageview(); } catch(err) {} ml> l>