Install
$ gem install rack-debug
Rails
# config/environments/development.rb
config.gem 'rack-debug'
config.middleware.use 'Rack::Debug'
# RAILS_ROOT/Rakefile
require 'rack-debug/tasks'
Middleware
# add a use line to your builder
require 'rack/debug'
Rack::Builder.new do
use Rack::Debug
run MyApp.new
end
# can optionally specify where to put the sockets
use Rack::Debug, :socket_path => '/tmp/rack-debug'
# Rakefile
require 'rack-debug/tasks'
Add breakpoints to your code
@user = User.find(params[:id])
debugger
render :show
Debugging:
# run the rake task,
$ rake debug
Connected.
# refresh a page in your browser, your app will break at debugger statements
(rdb:1) p @user
#<User id: 1, name: "David Dollar", email: "[email protected]", created_at: "...", updated_at: "...">
# can specify the socket path
SOCKET_PATH=/tmp/rack-debug rake debug
Meta:
Author/Maintainer: David Dollar
Patches contributed by:
Bart Teeuwisse
Thanks to:
Rack::Bug for a good example of Rack middleware in Rails
Ben Scofield for making me want to build some Rack middleware