Skip to Content
Ruby on Rails® for Microsoft Developers
book

Ruby on Rails® for Microsoft Developers

by Antonio Cangiano
April 2009
Intermediate to advanced content levelIntermediate to advanced
479 pages
12h 55m
English
Wrox
Content preview from Ruby on Rails® for Microsoft Developers

6.7. Debugging

Debugging is another important aspect of developing Rails applications. When something goes wrong it's fundamental to be able to understand what exactly is happening, as well as evaluate expressions and easily move around within the code.

As a Microsoft developer, you are probably accustomed to the excellent debugging support offered by Visual Studio and .NET. Having programmed in both environments, I can confirm that the level of support and convenience for debugging offered by .NET was way beyond what the Ruby world had to offer.

Ruby In Steel, covered in Chapter 1, enables you to work with Rails in Visual Studio and provides a fast debugger called Cylon.

Fortunately, there have been many efforts to improve this situation and Rails 2.x really simplifies the process of debugging applications by taking advantage of the fast ruby-debug gem. To perform fast debugging in Rails, three things are required:

  1. ruby-debug needs to be installed.

  2. You need to specify a "breakpoint" where you want the debugging session to start.

  3. The Web server needs to load the debugger.

Let's start by installing the ruby-debug gem. Run the following:

gem install ruby-debug

Notice that I opted not to add this as a prerequisite in config\environment.rb because it's a gem that's required for development purposes only.

Having installed ruby-debug, you can now place the method debugger anywhere you want in the application. Let's temporarily add it to the index action of the Articles controller ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Michael Hartl

Publisher Resources

ISBN: 9780470374955Purchase book