如何构建 rake 任务
我想了解如何为我的 Rails 3 应用程序构建一个有两件事的 rake 任务。
- 将资产推送到 CDN
- 部署到 heroku
上述步骤的命令:
rake cache:s3
heroku jammit:deploy --app #{app}
这是我的 /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
但出现 'undefined method `shell' for main:Object' 的错误
建议如何进行这项工作?这应该是一项任务还是其他什么?
谢谢
I'd like to learn how to build a rake task for my rails 3 app that does two things.
- Pushes assets to the CDN
- Deploys to heroku
Commands for the above steps:
rake cache:s3
heroku jammit:deploy --app #{app}
Here's what I have /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'
Suggestions on how to make this work? Should this be a task or something else?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个任务是另一个 rake 任务,如果它是
:deployit
任务的依赖项,它将运行。您当前的代码将加载 rake 两次。如果您使用 Arun 建议的系统,您将得到:
The first task is another rake task, which will run if it is a dependency of the
:deployit
task. Your current code would loads rake twice.If you use system like Arun suggested you would get:
请改用系统命令。有关更多信息: http://blog.jayfields .com/2006/06/ruby-kernel-system-exec-and-x.html
Use system command instead. For more info: http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html