Ruby In Steel Archives

Back to -Ruby In Steel Archives

Debugging Ruby On Rails Applications with LightTPD and Cylon

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!

Bookmark and Share   Keywords:  ide  rails
© SapphireSteel Software 2014