SapphireSteel Software

 

  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
     

 

  rss
RSS (SITE)
 
  rss
RSS (BLOG ONLY)
 
   
 
 
     

 

Section :: Ruby In Steel Archives
- Format For Printing...

Debugging Rails Applications

by Huw Collingbourne
Saturday 5 August 2006.
 

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.

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…

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…

Debug!

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

AddThis Social Bookmark Button

Forum

  • Debugging Rails Applications
    5 November 2006, by Hari

    Hi, This promises to be a great IDE for rails development. I just installed the IDE loaded an existing project, followed the instructions and I get this error

    Execute failed: The system cannot find the path specified

    I have no clue what this is talking about. Can anyone explain how to fix this?

    Thanks, Hari

  • Debugging Rails Applications
    5 August 2006, by Drazen Dotlic
    This is way too complicated. I am sure you are aware how this works in other similar situations. The project settings (for all the "normal" project types in Visual Studio) have a startup exe setting where you can set up which executable to start when debugging. You can also provide parameters to this executable. This setup is used all the time when what you are building is NOT an executable and you need an exe to "host" your project output (be it DLL, an add-in to some other app or a set of Ruby files that are "hosted" in the Webrick server). It would be great if you could support this model.
    • Debugging Rails Applications
      5 August 2006, by Dermot

      You are right - it is too complicated. In the commercial edition, it will be done differently.

      But I think that this is the least of the problems. The main problem is that it’s WAY too slow. The second problem is that you can’t put a breakpoint in a mixed Ruby and HTML file - you can only place them in ’pure’ Ruby code.

      We introduced this really to show that you can debug Rails applications in Visual Studio and to give at least one way to do it. We are planning a much faster debugger (hopefully you wont notice that it is there) and one that will allow full Rails debugging.

      But this is a few months off, yet.

      • Debugging Rails Applications
        7 August 2006, by Drazen Dotlic

        You are right - it is too complicated. In the commercial edition, it will be done differently.

        Glad to hear that.

        The main problem is that it’s WAY too slow.

        It’s not a huge problem for Rails applications. I tend to use debugger often in situations where:

        1. I can’t test something with unit/functional tests

        2. I have a desktop application with very complicated interactivity between user and app, app and network, app and filesystem or all of this at the same time

        With Web apps, I have had very little need of debugging. On the other hand, when I do need it, I’d rather stay in Visual Studio and use known keyboard shortcuts and a nice environment.

        Getting it a lot faster is always better, though. Do you have any idea on the pricing of the commercial edition (at least roughly?).

        • Debugging Rails Applications
          7 August 2006, by Huw

          Just to clarify (in case my little debugging guide makes it look more complicated than it really is) - the steps to debug are:

          - Set breakpoints
          - Load the program to be debugged (i.e. the server script)
          - Set its debug properties to a) Arguments = the port number; b) BuildAction = Ruby, c) the Application directory
          - Press F5

          Now run your Rails application.

          I suspect it may look more complicated as my guide tries to go into every little step, menu item and keystroke. That said, as Dermot has already made clear, the Debugger in this edition is absolutely not the debugger that will be in the commercial release. We want the commercial debugger to be both simpler to use and much faster in execution. I’m glad you find the speed of the current debugger to be acceptable. Personally, I find it to be painfully slow. That’s not just the debugger in Ruby In Steel but the underlying Ruby debugger itself. It also doesn’t provide me with enough debugging information as I would ideally like. We shall be addressing all of these problems in the debugger which is currently under development.

          I’m afraid we aren’t ready to announce the price of the Developer Edition yet. We’ll have more to say on that in a few months.

          best wishes

          Huw

          • Debugging Rails Applications
            10 August 2006, by Drazen Dotlic

            I’m glad you find the speed of the current debugger to be acceptable. Personally, I find it to be painfully slow.

            Well, I’m not saying it’s not slow :), but compared to alternatives I find it great that I don’t have to leave the IDE and can use familiar watch windows to inspect variable values. Or, God forbid, use "puts" to spit out debugging information :(

            Keep up the good work.

 

© 2008 SapphireSteel Software. All rights reserved