尽管这听起来可能与您在此处找到的其他问题相似,但有一点不同。我有两个目录,比如 /home/rails/Rake 和 /home/rails/test_app。rails 目录是我放置所有 rails 项目的地方。
在 Rake 内部,我有一个Rakefile和一个create.rake文件。
这就是我的rakefile的样子
namespace :setup do
desc "something"
task :init do
print "Name of the destination directory: "
name = STDIN.gets.strip
cp_r '.', "../#{name}/lib/tasks"
cd "../#{name}"
sh "rake setup:create"
end
end
并创建.rake
namespace :setup do
desc "Install"
task :create do
sh 'git init'
#some other code
end
end
它的作用是显而易见的。我想将 Rake 目录的内容复制到 /test_app/lib/tasks。然后将目录更改为 test_app 并运行 setup:create task 在 install.rake 文件中定义,现在放置在 test_app/lib/tasks 中。这行得通,但这是这样做的耙子方式吗?任何人都可以给我一点提示,它是如何完成的,Rake 方式。
这是我使用调用方法时遇到的错误:
$ rake setup:init
Name of the destination directory:
testapp
cp -r . ../testapp/lib/tasks
cd ../testapp
rake aborted!
Don't know how to build task 'setup:create'
/home/TradeRaider/rails/Rake/Rakefile:8:in `block (2 levels) in <top (required)>'
/home/TradeRaider/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/home/TradeRaider/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => setup:init
(See full trace by running task with --trace)