Ruby In Steel Archives

Back to -Ruby In Steel Archives

Debugging Rails Applications

Ruby In Steel beta 0.75 (due to be released in mid-August, 2006) provides debugging for Rails applications in addition to the ‘pure Ruby’ debugging provided in earlier releases. Here is a brief preview walkthrough of its Rails debugging features.

Please bear in mind that…
- This only works with beta 0.75 or higher or Ruby In Steel
- This assumes you already have a working Rails application
- This is not the fast debugger which will be in the Developer edition of Ruby In Steel

OK, so let’s get started. First load your Rails application into Ruby In Steel (0.75 or higher). Here, I am using the Blog application discussed elsewhere.

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. Here I have set breakpoints in blog_controller.rb.

Load Server File

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

Set Server File Properties

With server still selected in the Solution Explorer, you will need to set these properties in the Properties panel…
- Arguments – enter -p followed by the port number used by the WEBrick server. This is likely to be -p3000 but it may have some other value (as here, where it is: -p3003).
- Build Action – by default for a file such as server which has no file extension, this is set to Content. But we want to run this as a Ruby file so you must set this property to: Ruby.
- Working Directory – This needs to be set to the top-level directory of the Rails application. For example, here, the server file is in the directory: G:\rails\test\RailsDebugTest\script\server so I have set the Working Directory to: G:\rails\test\RailsDebugTest\

Make Server The Active File

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

Start Debugging

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

Wait For Server To Start

After a few second (be patient, this is not instantaneous!) the WEBrick server will start up and display this output in the Ruby console.

- 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…

Load Application Into Web Browser

Load up a Web Browser (this may either be a standalone browser or, as seen here, 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.

Here I have entered: http://localhost:3003/blog which is the full address – including the host name and port - to my Blog application. I previously put a breakpoint on a method which is called when I enter a new post; I am clicking the New post link which should run the bit of code I want to debug…

Hit Breakpoint

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


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

For more help see:
- Ruby In Rails Development with Steel
- Debugging Ruby
- Debugging Demo Movie
- Create a Weblog with Ruby In Steel

Bookmark and Share   Keywords:  ide  rails
© SapphireSteel Software 2014