[英]how to build a rake task
I'd like to learn how to build a rake task for my rails 3 app that does two things. 我想学习如何为我的Rails 3应用程序构建一个完成两件事的rake任务。
Commands for the above steps: 以上步骤的命令:
rake cache:s3
heroku jammit:deploy --app #{app}
Here's what I have /lib/tasks/deployer.rake 这是我的/lib/tasks/deployer.rake
task :deployit do
puts '=== Storing assets on s3 ==='
run "rake cache:s3"
puts '=== Deploying to Heroku ==='
run "heroku jammit:deploy --app #{app}"
end
def run(cmd)
shell cmd
if $?.exitstatus == 0
display "[OK]"
else
display "[FAIL]"
end
end
But that errors with 'undefined method `shell' for main:Object' 但是,main:Object的“ shell的未定义方法”错误
Suggestions on how to make this work? 有关如何进行这项工作的建议? Should this be a task or something else?
这应该是任务还是其他?
Thanks 谢谢
Use system command instead. 请改用系统命令。 For more info: http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html
有关更多信息: http : //blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html
The first task is another rake task, which will run if it is a dependency of the :deployit
task. 第一个任务是另一个瑞克任务,如果它是
:deployit
任务的依赖项,则它将运行。 Your current code would loads rake twice. 您当前的代码将两次加载rake。
If you use system like Arun suggested you would get: 如果使用像Arun这样的系统,您将获得:
task :deployit => 'cache:s3' do
puts '=== Deploying to Heroku ==='
system "heroku jammit:deploy --app #{app}"
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.