---
title: "遇到 rake 0.9.0 bug"
author: "fsword"
date: "2011-05-31T12:01:53Z"
tags: []
categories: ["编程语言"]
slug: "rake-0-9-0-bug"
draft: false
lastmod: "2011-05-31T12:02:21Z"
id: 1066135
url: "https://fsword.iteye.com/blog/1066135"
---

最近突然发现执行 rake 时遇到问题

$ rake -T  
rake aborted!  
undefined method \`task' for #&lt;Demo::Application:0x2b3a0934&gt;

(See full trace by running task with --trace)

上网看了一下是 rake 的 bug ，参考[这里](http://stackoverflow.com/questions/5287121/undefined-method-task-using-rake-0-9-0 "也许被墙了")

 

看E文可能比较累，这里简单列出解决办法：

修改 rails 项目的 Rakefile 文件，在 require 'rake' 之后加入下面一段：

```
class Rails::Application
  include Rake::DSL if defined?(Rake::DSL)
end
```

 

另外，如果用了项目模板，可以这么加入：

```
# monkey patch: rake 0.9.0 bugfix
gsub_file 'Rakefile', /require\ 'rake'/, %Q[require 'rake'

class Rails::Application
  include Rake::DSL if defined?(Rake::DSL)
end]
```

 

open class 就是好！