2011-03-13 129 views
2

我有一個微不足道的rake腳本來刪除網頁。它的路徑是lib/tasks/scrape.rake。當運行rake db時,rails rake運行lib/tasks/scrape.rake:migrate

[email protected]:~/snowcrash$ ls lib/tasks/ 
scrape.rake 

我也有一些DB數據庫遷移腳本/遷移:

[email protected]:~/snowcrash$ ls db/migrate/ 
20110307213515_create_questions.rb 
20110310010000_create_answers.rb 
20110313191820_add_question_id_to_answers.rb 

問題是,當我運行耙分貝:遷移。這似乎也跑我的lib /任務/ scrape.rake任務:

[email protected]:~/snowcrash$ rake db:migrate 
(in /home/dan/snowcrash) 
Fetched document: http://www.baidu.com/s?wd=love+me 
\t Content Type: text/html\n 
\t Charset: gbk\n 
\t Content-Encoding: \n 
\t Last Modified: \n\n 
== AddQuestionIdToAnswers: migrating ========================================= 
-- add_column("questions", "answer_id", :integer) 
    -> 0.4923s 
-- add_index("questions", "answer_id") 
    -> 0.4954s 
== AddQuestionIdToAnswers: migrated (0.9881s) ================================ 

我做了一些google搜索,發現這個文檔:http://jasonseifer.com/2010/04/06/rake-tutorial。他指出:

Rails將在lib/tasks中自動提取任務 。

如何讓「rake db:migrate」不能運行我的其他rake任務?我有什麼選擇?

回答

4

沒有看到你scrape.rake任務的內容,這是很難確定這是怎麼回事,但我的猜測你刮任務的功能實際上並沒有在任務結束了。例如,這裏有一個適當的耙子任務:

desc "Output something on the command line" 
task :output_stuff do 
    puts "I'm outputting stuff!" 
end 

如果您.rake文件,而不是內容只是:

puts "I'm outputting stuff!" 

那麼當Rails的加載你的rake任務,代碼,立即執行(Rake任務畢竟是用Ruby編寫的!)

所以,檢查一下,並讓我知道我是否遠離基地。

+0

你完全正確。我沒有把它包裝在一個任務中! :d – sybind 2011-03-13 20:24:32

相關問題