Ruby 使用rake任务与heroku接口

Ruby 使用rake任务与heroku接口,ruby,rake,Ruby,Rake,我在使用FileUtils的Rails 4应用程序中运行Rake命令时遇到问题。我使用RVM作为版本管理器,似乎无法解决问题。我得到的错误是: $ rake db:clone_production:to_local --trace ** Invoke db:clone_production:to_local (first_time) ** Execute db:clone_production:to_local heroku pgbackups:capture --expire -r produ

我在使用FileUtils的Rails 4应用程序中运行Rake命令时遇到问题。我使用RVM作为版本管理器,似乎无法解决问题。我得到的错误是:

$ rake db:clone_production:to_local --trace
** Invoke db:clone_production:to_local (first_time)
** Execute db:clone_production:to_local heroku pgbackups:capture --expire -r production
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
rake aborted!
Command failed with status (18): [heroku pgbackups:capture --expire -r produ...]
/Users/trevor/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/file_utils.rb:54:in `block in create_shell_runner'
... Some more stack trace ...
其他Rake任务正常工作,例如
$Rake db:migrate
,但我似乎无法运行shell脚本。Rake任务如下所示:

# ./lib/tasks/db.rake
namespace :db do
  ...
  namespace :clone_production do
    desc "Clone production database to local database"
    task :to_local do
      sh "heroku pgbackups:capture --expire -r production"
      file = "tmp/db/backup_#{ Time.now.getutc.to_s.gsub(/ /, /_/) }.dump"
      sh "curl -o #{ file } `heroku pgbackups:url -r production`"
      sh "pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d myapp_development #{ file }"
    end
  end
end
我的道路看起来不错:
/Users/trevor/.rvm/gems/ruby-2.0.0-p195@myapp/bin:/Users/trevor/.rvm/gems/ruby-2.0.0-p195@global/bin:/Users/trevor/.rvm/rubies/ruby-2.0.0-p195/bin:/Users/trevor/.rvm/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/trevor/workspace/adt bundle mac/sdk/tools:/Users/trevor/workspace/adt bundle mac/sdk/platform-tools

我正在使用这些版本
Rake-10.1.0
Rails-4.0.0
,以及
ruby-2.0.0-p195

#./.ruby-version
2.0.0-p195

#./.ruby-gemset
myapp

所以我知道出了什么问题。当您运行rake任务时,Heroku工具带不会加载,这意味着您必须在开发组中安装Heroku gem,才能在rake任务中使用Heroku命令。只是一个人人都应该知道的带有Heroku工具带的gotchya。

您可以尝试在干净的环境中运行Heroku命令:

Bundler.with_clean_env { sh "heroku pgbackups:capture --expire -r production" }

项目文件夹中是否有
.rvmrc
文件?如果有,它包含什么?有.ruby版本,它包含2.0.0-p195