Ruby In Steel Archives

Back to -Ruby In Steel Archives

Debugging Rails With WEBrick or Mongrel

Ruby In Steel Developer provides debugging for Rails applications in addition to ‘pure Ruby’ programs. The Developer Edition features two debuggers – the fast ’Cylon’ debugger and the slower Ruby debugger. You can start a Rails debugging session by clicking the ’One-Click Rails Debugger’ button on the Ruby Toolbar.

Dedicated support is provided for the following web servers:

- WEBrick
- Mongrel
- LightTPD

Note: In the first release of Ruby In Steel, we recommended the use of the LightTPD server, due to technical limitations of the debugger. In the current release of Ruby In Steel, those limitations no longer apply and WEBrick or Mongrel can also be used with the Cylon debugger. For information on using LightTPD see: Debugging Debugging Ruby On Rails Applications with LightTPD and Cylon.

Create A Rails Project...

Create a Ruby On Rails project in the usual way (select New|Project|Ruby In Steel and click Rails Project).

To Select WEBrick...

Make sure WEBrick is selected as your server: select Tools|Options|Projects and Solutions and select Ruby In Steel. Set Web server script to webbrick_server.bat. (You can click the browse button [...] in order to select this file from an Open dialog. In the Options dialog, set the Rails debug script to webbrick_service.rb (once again you can browse and select this file). Optionally (but recommended), ensure Use the fast Cylon Debugger is checked. Either leave the WEBrick server port at its default value (3000) or, if this port is already in use (say by another server), set it to some other values (such as 3003). Click OK to close the dialog.

To Select Mongrel...

Make sure Mongrel is selected as your server: select Tools|Options|Projects and Solutions and select Ruby In Steel. Set Web server script to mongrel_server.bat. (You can click the browse button [...] in order to select this file from an Open dialog. In the Options dialog, set the Rails debug script to mongrel_service.rb (once again you can browse and select this file). Optionally (but recommended) ensure Use the fast Cylon Debugger is checked. The WEBrick server port will also be applied to Mongrel. Either leave the WEBrick server port at its default value (3000) or, if this port is already in use (say by another server), set it to some other values (such as 3003). Click OK to close the dialog.

Click and Debug...

Set breakpoints in any Ruby source files. Then, to start debugging, select One-click Rails Debugger from the Ruby menu. After a few seconds (be patient, this is not instantaneous!) the server will start up and display output similar to the following in the Ruby console...

Problems…?
- If you can’t see the Ruby Console, you can load it by selecting the View menu, Other Windows, then Ruby Console.
- If error messages appear in the Ruby Console, check that you have correctly set all the properties as explained earlier and that another instance of the WEBrick or Mongrel server is not already running. Fix the problems and try again…

Run Rails Application In Web Browser

Once you have started debugging a Rails application, you may load up a Web Browser in order to interact with it (this may either be a standalone browser or the integrated browser in Visual Studio – you can load this from the menus: View, Other Windows, Web Browser).

In the address bar, enter the full address to your Rails application just as you would if running it normally. For example, you might enter: http://localhost:3003/blog - that is, the full address, including the host name and port, to your application. Let’s assume you put a breakpoint on a method which is called when you enter a new post; you now click the New post link in the web browser which runs the bit of code you want to debug…

Stop On Breakpoint

The result is that the debugger stops on the line with the breakpoint…

Debug

And now you can use all the usual Ruby In Steel debugging features to trace through the code and monitor variables and expressions in the various debugging windows.

Bookmark and Share   Keywords:  ide  rails
© SapphireSteel Software 2014