$ sudo gem install ruby-debug
▲To debug simple Ruby scripts, just run your scripts with rdebug rather than ruby
▲Debugging Rails with ruby-debug
- Require the ruby-debug library from config/environments/development.rb so that it is only loaded in the development environment:
- Insert a call to debugger anywhere you want to stop the application’s execution and drop into the debugger.
class SignupController < ApplicationController
@query = params[:q]
- Start up the Rails server. The debugger only works with WEBrick and Mongrel,
because the running code still has access to the tty under those servers.
Under FastCGI, the worker processes would not be able to interact with the
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
- Interact with your application as needed to trigger the debugger. The request will hang in the browser, and the server console will drop into the debugger console and show the line of code it is paused on:
app/controllers/signup_controller.rb:5 @query = params[:q]