#54 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:
- mp4Full Size H.264 Video (14.6 MB)
- m4vSmaller H.264 Video (8.69 MB)
- webmFull Size VP8 Video (26.5 MB)
- ogvFull Size Theora Video (22.6 MB)
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!
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!
@Pratik, cool, thanks. Didn't know about this.
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.
Great tutorial, thanks!
Btw, Date.today + 10.days has been fixed in edge.
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...)
@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.
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?
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
@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
Upgrading to ruby 1.8.6 from 1.8.5 has fixed the problem.
Mike
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
@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. :)
My fav screencast along with the other 53 :)
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.
great job Ryan
Love this one.
Are there other debugging tools for Rails?
Thank you so much for this and rest of the Railscasts. This saved my butt today!
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 :(
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
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
is there a way to keep from having to step through rails own libraries ? I'm only interested in my code. Thanks.
at 5:12 where does come from the `y` in the `y due_date` command in the irb session?
@dEAN : use the command `next` instead of `step`
Thank you. Very useful
gem install ruby-debug19
for ruby 1.9 compatibility :
http://isitruby19.com/ruby-debug
The ruby-debug Basics [screencast] link is broken
ruby-debug interesting application!!i will try
This episode has been updated to Rails 5 as a blog post Debugging Using ByeBug gem in Rails 5