2014-02-05 141 views
2

我正在使用rails 4,我需要添加一个子任务来为我们的数据库使用演示数据(产品演示)进行种子播种。我想让它成为一个名为rake db:seed:demo的子任务,我该怎么做?添加子任务耙

我试图使用此代码的子任务,但我从耙子说没有找到任务的错误。

#!/usr/bin/env rake 
# Add your own tasks in files placed in lib/tasks ending in .rake, 
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 

require File.expand_path('../config/application', __FILE__) 

API::Application.load_tasks 

task :demo => :seed do 

end 

task :seed => :db 

回答

5

使用namespace指令:

namespace :db do 
    namespace :seed do 
    task :demo do 
    end 
    end 
end 
+0

完美的男人,感谢发帖 –