SapphireSteel Software

 

  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
     

 

  rss
RSS (SITE)
 
  rss
RSS (BLOG ONLY)
 
   
 
 
     

 

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

Debugging Ruby On Rails Applications with LightTPD and Cylon

by Dermot Hogan
Saturday 13 January 2007.
 

Debugging Rails applications in the past has been slow and tedious. But with a combination of LightTPD and Ruby In Steel Developer’s fast Cylon debugger. It’s a breeze. You will need to do a (once only) bit of setting up, however. Here’s a step-by-step guide on how to go about it.

Note: You can also debug using other servers. Indeed, it is easier to set up and use either the WEBrick or Mongrel server. However, LightTPD is generally quite fast and is favoured by some Rails developers. Full details of configuring and using these three servers are given in the manual. See also: Debugging Rails With WEBrick or Mongrel

First off, I assume that you will have Ruby, Visual Studio and Ruby In Steel Developer installed.

First, Get Everything Installed

The steps below explain how to install all the components required in order to run LightTPD with SCGI (which is needed in order that LightTPD can interface with Rails):

- If you haven’t got Rails installed, then the first step is to install it. From a command prompt type:
gem install rails
and answer ‘Y’ to any questions about required dependencies.
- Install the cmdparse gem:
gem install cmdparse
- Install the highline gem
gem install highline

Note: as a shortcut to running Gems, use the Gems dialog, from the Ruby menu. In this case, you only need to enter the name of the Gem itself:
rails
cmdparse
highline

- Download Zed Shaw’s SCGI gem ( at the time of writing this is version 0.4.3) and the gem file name is scgi_rails-0.4.3.gem ) to a temporary directory. Change to the directory where you downloaded the scgi gem and install it. This time, you will have to do it from the command prompt rather than the Gem dialog, as you are not installing this gem from an online repository:

cd \temp
gem install scgi_rails-0.4.3.gem

- Download LightTPD for Windows. At the time of writing, the current version is 1.4.13 and the downloaded installer is called lighttpd-1.4.13-win-setup.exe. Run the installer. Note that, by default, LightTPD installs itself into the directory C:\lighttpd - and it is recommended that you leave it here. Move it anywhere else and you are on your own.

Now Create Your Project

- Create a new Rails project in Ruby In Steel. Select New|Project|Ruby In Steel and click Rails Project. Give the project a name (’Rails1’ should do) and click OK.
- When the Create Rails Project dialog appears, click ’None’ in the ’Select database options’ group at the top left then click OK.
- At this point a dialog appears showing some details about the project you are starting. Click Proceed.
- After a few moments, the project will be created. You are now ready to set the web server script to LightTPD: select Tools|Options|Projects and Solutions and select Ruby In Steel. Set Web server script to lighttpd_server.bat’ (You can click the browse button [...] in order to select this file from an Open dialog).

- In the Options dialog box, set the Rails debug script to scgi_service.rb (once again you can browse and select this file).
- Ensure Use the fast Cylon Debugger is checked. The server port shown in this dialog is only used when running a server script (for example, with WEBrick) and is not relevant to LightTPD.
- Click OK to close the Options dialog.
- Start LightTPD. Select Ruby|Start Server. You should see a command window appear that is running the LightTPD server:

NOTE: If, at this stage, you see an error message stating that "port: 80" is already in use, you will need to edit LightTPD’s port manually to some other value. This is set in the LightTPD configuration file, lighttpd.conf, in the \config directory under your current Rails application’s directory. Open this file in Visual Studio and search for the following entry:
#server.port  = 81
and remove the comment ’#’, so that the entry is now:
server.port  = 81
Save the file and try to start LightTPD again (as explained above).

Click-and-Debug!

- We are now going to check that all is well by starting Rails and displaying its welcome page. To do this, select Ruby|One-click Rails Debugger from the Ruby menu. You should see the Visual Studio Ruby console displayed with something like the following text:

- Check that Rails is running by entering the following URL in a browser (note: if you edited the port number in the config file, remember to substitute 81 or whatever port number in the address entered) :
http://localhost:80/ You should get the Rails intro page:

- Stop Rails. Select Debug|Stop Debugging.
- Now add a controller to Rails. To generate a controller, select Ruby|Generate and ensure the Controller radio button is selected. Set the Value textbox to "helloworld". Then click OK.

- Open /app/controllers branch of the Solution Explorer and open the file helloworld_controller.rb. Add the following code after the class declaration in this file and before the end keyword:

def index
  render :text => “hello world”
end

Save the file.
- Set a break point on the render :text line and Start the Rails debugger again by selecting Ruby|One-click Rails Debugger.

- In your web browser enter:
http://localhost:80/helloworld
The Rails program should now breakpoint and you should see

- Continue by pressing F5. you should now see the "hello world" page displayed

- And that’s it!

AddThis Social Bookmark Button


Forum

  • Debugging Ruby On Rails Applications with LightTPD and Cylon
    22 January 2007

    will it be possible to debug rhtml files? or will debugging only works in controllers? (pure ruby files)

    • Debugging Ruby On Rails Applications with LightTPD and Cylon
      22 January 2007, by Huw

      Currently we only debug into Ruby code files. The way it works is that you can interact with your application in a web browser (the html at this stage doesn’t contain any embedded Ruby so that code is not availble to us). When, as a result of that interaction, some Ruby code is executed (controller, model, helper etc.) the debugger is able to go into action with breakpoints, watches, tracing etc.

      Whether or not it is, in principle, possible to debug embedded Ruby is an interesting question. It’s one we’ll need to give some thought to ;-)

      best wishes

      Huw

  • Debugging Ruby On Rails Applications with LightTPD and Cylon
    14 January 2007, by glenn

    Looking forward to getting the dev version. I’m checking your site daily for info, Good luck and great work!!!

  • Debugging Ruby On Rails Applications with LightTPD and Cylon
    13 January 2007, by Brian Moelk

    What about using another one of Zed’s creations...Mongrel?

    • Debugging Ruby On Rails Applications with LightTPD and Cylon
      13 January 2007, by Dermot

      I would be delighted to - if I could get it to work!

      I’ve had several attempts at installing mongrel ... so far without success.

      The latest version (RC1) got the furthest - but I could not get the service working. So I’m waiting until Zed & company sort it all out.

      Unfortunately, I just dont have time right now to figure out what’s going on.

      Dermot

    • Debugging Ruby On Rails Applications with LightTPD and Cylon
      13 January 2007, by Dermot

      I should also point out that the Cylon debugger isn’t thread safe yet. This means that it probably will not work correctly with any Ruby software that uses threads in a serious fashion - WebBrick certainly causes trouble. SCGI is very good in this respect in that its use of threads is minimal.

      As we’ve indicated in the Roadmap, a multithreaded Cylon will be coming out in a few months time.

      Dermot

      • Debugging Ruby On Rails Applications with LightTPD and Cylon
        9 April 2007, by Huw

        Just to update the above: Cylon is now thread-safe and can be successfully used with Mongrel and WEBrick in addition to LightTPD.

 

© 2009 SapphireSteel Software. All rights reserved