Coming from PHP I used to rely heavily on the die() command to print out debugging information. In rails nobody could really tell me if there was an equivalent, I was told to “raise”, which I’m sure everyone feels is a bit dirty to use. So I thought I’d quickly put up a few ways I debug in Rails.
Its a sexy little gem that lets you easily step through your code and even drop into an IRB session. To use it, make sure you have the gem or plugin installed and then.
require 'ruby-debug'; debugger
Ruby debug shines when running a script/server (mongrel, webrick, etc) but can also be used with passenger, but with limitations.
This is equivelent to the PHP die() command. It takes an argument, evals and prints the statement to the screen. Note that it does halt execution.
This is a nice hacky way to print something out to the screen very fast, no matter where you are in your application.
Debug lets you easily eval something to a screen in your views.
Now that you have a bunch of debugging commands with rails, please stop using raise() to debug!