---
title: "passenger也可以debug"
author: "t0uch"
date: "2009-12-17T15:23:48Z"
tags: []
categories: ["编程语言"]
slug: "passenger-debug"
draft: false
lastmod: "2009-12-17T15:35:14Z"
id: 550570
url: "https://t0uch.iteye.com/blog/550570"
---

最近在做一个东西，要用到subdomain，发现webrick不能支持，所以寻找passenger进行debug的方法。

方法比较土，但还是管用的。

首先，往development.rb里加入

```ruby
if File.exists?(File.join(RAILS_ROOT,'tmp', 'debug.txt'))
  require 'ruby-debug'
  Debugger.wait_connection = true
  Debugger.start_remote
  File.delete(File.join(RAILS_ROOT,'tmp', 'debug.txt'))
end
```


接着在lib/task目录下新建restart.rake文件，内容为

```ruby
task :restart do
  system("touch tmp/restart.txt")
  system("touch tmp/debug.txt") if ENV["debug"] == 'true'
end
```


目前为止基本上搞定了，不过这些前提是已经安装了ruby-debug，rdebug这个命令可以执行。

这里是nginx，用development模式运行rails，在需要debug的地方加入一行"debugger"，debug的时候在这里break。然后运行rake restart DEBUG=true。

打开浏览器，输入可以跑到刚刚输入debugger的url，会发现页面停止在那里。
这个时候，到terminal输入rdebug -c，怎么样，看到熟悉的debug界面了吧？

另外，在home建立一个文件.rdebugrc，设置一下debugger效果会好一些

```ruby
set autoeval
set autolist
set autoreload

```