Ruby In Steel :: Help Index :: SapphireSteel Software Front Page Return to the Index
Debugging Rails With WEBrick
See Also

Glossary Item Box

This is a detailed guide to debugging Ruby In Rails applications using the (slow) Ruby debugger and the WEBrick server as an alternative to the fast Cylon debugger and LightTPD. If you just need a quick reminder of the necessary steps, refer to the Quick Guide To Debugging Rails via the Server Script.

Before you begin, make sure that the appropriate options have been selected. Ensure that the Web server script is set to webbrick_server.rb and the Rails debug script is set to webbrick_service.rb. Also ensure that the Use the fast Cylon debugger option is not selected. All these options may be set in the Projects and Solutions/Ruby In Steel page of the Options dialog available from the Tools menu.

1) Set Breakpoints

Start off by setting breakpoints in your Ruby (.rb) files  (not in RHTML files). Set breakpoints by double-clicking in the left-hand margin.

2) Load Server script

Using the Solution Explorer find the server file in the \script directory and double-click to load it into the editor.

3) Set Server Properties

With server still selected in the Solution Explorer, you will need to set these properties in the Properties panel…

4) Make Sure The Server Script is selected

Make sure the server script is the active page in Visual Studio as we are about to run it…

5) Start Debugging

Start debugging by selecting a the appropriate menu item or pressing F5.

After a few seconds (be patient, this is not instantaneous!) the server will start up and display this output 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
   a) that server is the active page in the editor,
   b) that you have correctly set all the properties as explained earlier and
   c) that another instance of the WEBrick server is not already running. Fix the problems and try again…

6) Run Application In Web Browser

Load up a Web Browser (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…

7) Stop On Breakpoint

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

8) 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.

See Also