#54
Jul 06, 2007

Debugging with ruby-debug

This episode will show you how to debug a rails app using ruby-debug: set a breakpoint, inspect variables, change the code and more.
Download (21 MB, 8:03)
alternative download for iPod & Apple TV (11.9 MB, 8:03)

Resources

Special thanks to Mikel for informing me of this.

28 comments

Vlad Jul 06, 2007 at 00:00

+1 первыйнах


Mikel Lindsaar Jul 06, 2007 at 01:02

Heya Ryan, great screencast, much better than what I would have done, and you are welcome for the pointer :)

for more info, you can also type entire expressions into the debugger, like:

p Foo.find(:all, :conditions => { blah })

Basically, in the debugger, anything you could puts from the console, you can see.

Looking forward to your next great episode!


Mislav Jul 06, 2007 at 02:28

Awesome episode, thanks!


art Jul 06, 2007 at 02:38

I want a child from you!!!
Great episode


chineseGuy Jul 06, 2007 at 02:45

cool,thanks!


Pratik Jul 06, 2007 at 03:38

Hey Ryan,

Great cast. Just a little correction about what you said.

You said it may not be possible to use it with Apache/Lighty. Well, in theory it is.

You can just put following in your development.rb :

require 'ruby-debug'
Debugger.start_remote

Then from shell, do 'rdebug -c'.

Thanks!


BrianC Jul 06, 2007 at 06:48

Priceless. Many thanks!


Ryan Bates Jul 06, 2007 at 07:20

@Pratik, cool, thanks. Didn't know about this.


Swami Atma Jul 06, 2007 at 08:56

Great job as usual Ryan.

I like the 'acting' when, with your tone of voice, you pretend to be baffled by the mistake, and then, you feel relieved to have discovered the mistake.


Geoff Buesing Jul 06, 2007 at 09:36

Great tutorial, thanks!

Btw, Date.today + 10.days has been fixed in edge.


darryl west Jul 06, 2007 at 11:04

Great job as always. It's good to have another tool to use. but...

In practice, this method should have gone through unit testing, in fact even before the method was completed. Also if you use .to_date on the method parameter, you would get around any type issues.

(i know this was not the goal of this sreen cast, but i'm just saying...)


Ryan Bates Jul 06, 2007 at 11:13

@Swami, LOL.

@Geoff, that's awesome. I didn't know that. Looks like adding 1.year or 1.month is smarter as well. It no longer does a simple convert to 365 or 30 days. I can't wait until 2.0 is released!

@darryl, good point. I had trouble coming up with an example for using ruby-debug since most situations are more complex than what can be covered in a short screencast.


David Parker Jul 06, 2007 at 13:01

Great job Ryan! Loved the last 3 Railscasts...

Idea for your list of Railscasts: how to work with different database types and different server types?


Mike Stramba Jul 06, 2007 at 18:52

Ryan,

On Win XP : I'm using InstantRails:
- Ruby 1.8.5
- Rails 1.2.3
- Active Record 1.15.3

I installed ruby-debug and it works fine in Mongrel but when I load a console (ruby script\console), I get the following errors : http://pastie.caboo.se/76785


Ryan Bates Jul 06, 2007 at 19:37

@Mike, hmm, I'm not sure what the problem is. Perhaps the gem is being required too early. You might want to try this: http://pastie.caboo.se/76786


Mike Stramba Jul 08, 2007 at 04:55

Upgrading to ruby 1.8.6 from 1.8.5 has fixed the problem.

Mike


Bobby Santiago Jul 08, 2007 at 18:19

Hey, Ryan - I would like to propose having a Railscast Wishlist feature; this is becoming one of the best resources for Rails learning, I'm sure you could get a lot of ideas for screencasts from your avid "fans" out there!

Bobby


Ryan Bates Jul 08, 2007 at 19:01

@Bobby, that's a good suggestion, but I don't know if I will ever get around to implementing it. For now please email feedback [at] railscasts [dot] com if you wish to make a suggestion.

I'm planning to add a poll to the site in the near future, so you can vote on what you want to see. :)


carmelyne Jul 08, 2007 at 21:10

My fav screencast along with the other 53 :)


RainChen Jul 10, 2007 at 12:32

so, why not just build a poll app with Rmagic or sth else.
I think many guys will meet the image process app soon or later.


Bob Aug 11, 2007 at 20:59

great job Ryan


John Aug 12, 2007 at 19:45

Love this one.

Are there other debugging tools for Rails?


Hardbap Sep 08, 2007 at 12:54

Thank you so much for this and rest of the Railscasts. This saved my butt today!


amma Feb 11, 2008 at 09:59

hey, how about making a download section for all the videos in one place. All these videos are priceless , but a pain to download all one by one :(


Raul Parolari Mar 06, 2008 at 21:55

Hi, Ryan,

I played with the "error" that you showed in your screencast, but the expression works now fine in Rails (I should say in ActiveSupport); doing the calculation now (it is March 6 as I write):

Date.today + 10.days -> Sun, 16 Mar 2008

I was stunned, and I used the debugger to step through in ActiveSupport; it's a long story, but basically it does not evaluate inmediately '10.days'.

Rather it ends up with an array of "parts" [[:days, 10]], that allows to do the right thing when finally doing the sum.

I know that your point was to show the debugger, but I wanted to let you know that perhaps the example should be updated, if you ever have the chance.

[By the way, as many others, I love your screencasts]

Raul


kino May 23, 2008 at 01:55

We can be sure that an object inhibits acceptance of the all-embracing consciousness of internal time as existent by a freely actualizable return to multiplicities of the Objective world.


Yukti Jun 02, 2008 at 05:56

Hie

I am using WAMP
I have rails 2.0 installed
I installed gems debugger
but the require 'ruby-debug'
is giving problems
The moment I start my server I get these on the command prompt

=> Booting WEBrick...
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/webrick.rb:13: w
arning: already initialized constant OPTIONS
=> Booting WEBrick...
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/webrick.rb:13: w
arning: already initialized constant OPTIONS
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_re
quire': no such file to load -- c:/ruby/lib/ruby/gems/1.8/gems/linecache-0.42-ms
win32/lib/../ext/trace_nums (MissingSourceFile)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
quire'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_suppo
rt/dependencies.rb:496:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_suppo
rt/dependencies.rb:342:in `new_constants_in'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_suppo
rt/dependencies.rb:496:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/linecache-0.42-mswin32/lib/traceline
s.rb:8
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `ge
m_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `re
quire'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_suppo
rt/dependencies.rb:496:in `require'
... 39 levels...
from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:3
9
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `ge
m_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `re
quire'
from script/server:3

Please help.

regards
Yukti


dEAN Jul 23, 2008 at 12:50

is there a way to keep from having to step through rails own libraries ? I'm only interested in my code. Thanks.

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(required)

subscribe:
sponsored by:
if you want to help:
required:
Get Quicktime Player