Ruby on Rails
HowtoDebugWithRubyDebug (Version #14)

Ruby-Debug uses rdebug (instead of irb) as the debugger when you run a Ruby on Rails app.
This means that you can see the code around your breakpoint, and examine variables more easily.

Ruby-debug Home Page

an (outdated) example


Instructions

(These steps were tested using Ruby 1.8.6 and Rails 1.2.3. They should work for earlier versions as well, unless ruby-debug specifically says ‘Nope!’. The install and usage will probably be different once Rails 2.0 comes out.)

  • To install, type:

gem install ruby-debug

  • In your config/environments/development.rb file, add this to the bottom line:

require 'ruby-debug'

  • Then, if using mongrel or webBrick (lighttpd or anything using FastCGI won’t work with this), start your server as normal:

script/server

  • (In EDGE Rails and Rails 2.0, it should be possible to use the—debugger flag when starting the server: script/server --debugger or ruby script/server --debugger for Windows people)
  • In your code, add debugger to the lines where you want to inspect your code (use just like breakpoint)
  • When your application gets to that point, the console window in which you started the server will drop into the debugger program where you can play with it!
  • Typing help will allow you to see a list of commands: help command will give you more detail on each one.
  • If you want to inspect variables once in debugger mode, you can type p insert_variable_name_here to print it. Also typing “set autoeval” makes everything you type print out.
  • Since you aren’t exactly in a console mode by default, type irb to drop into an interactive ruby console (equivalent to irb or script/console). Now you can really have fun!

- Adam G.


Ruby-Debug uses rdebug (instead of irb) as the debugger when you run a Ruby on Rails app.
This means that you can see the code around your breakpoint, and examine variables more easily.

Ruby-debug Home Page

an (outdated) example


Instructions

(These steps were tested using Ruby 1.8.6 and Rails 1.2.3. They should work for earlier versions as well, unless ruby-debug specifically says ‘Nope!’. The install and usage will probably be different once Rails 2.0 comes out.)

  • To install, type:

gem install ruby-debug

  • In your config/environments/development.rb file, add this to the bottom line:

require 'ruby-debug'

  • Then, if using mongrel or webBrick (lighttpd or anything using FastCGI won’t work with this), start your server as normal:

script/server

  • (In EDGE Rails and Rails 2.0, it should be possible to use the—debugger flag when starting the server: script/server --debugger or ruby script/server --debugger for Windows people)
  • In your code, add debugger to the lines where you want to inspect your code (use just like breakpoint)
  • When your application gets to that point, the console window in which you started the server will drop into the debugger program where you can play with it!
  • Typing help will allow you to see a list of commands: help command will give you more detail on each one.
  • If you want to inspect variables once in debugger mode, you can type p insert_variable_name_here to print it. Also typing “set autoeval” makes everything you type print out.
  • Since you aren’t exactly in a console mode by default, type irb to drop into an interactive ruby console (equivalent to irb or script/console). Now you can really have fun!

- Adam G.