如何解决Heroku上未初始化的常量Rake :: DSL问题?

我收到类似于这些 问题中的错误,除了我在Heroku上发生的情况:

2011-05-30T09:03:29+00:00 heroku[worker.1]: Starting process with command: `rake jobs:work` 2011-05-30T09:03:30+00:00 app[worker.1]: (in /app) 2011-05-30T09:03:30+00:00 heroku[worker.1]: State changed from starting to up 2011-05-30T09:03:33+00:00 app[worker.1]: rake aborted! 2011-05-30T09:03:33+00:00 app[worker.1]: uninitialized constant Rake::DSL 2011-05-30T09:03:33+00:00 app[worker.1]: /app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>' 

这些问题的答案似乎是指定gem 'rake', '0.8.7'因为0.9版本导致的问题。

当我尝试添加gem 'rake', '0.8.7'到我的gemfile并推送到Heroku时,我得到这个错误:

 Unresolved dependencies detected; Installing... You have modified your Gemfile in development but did not check the resulting snapshot (Gemfile.lock) into version control You have added to the Gemfile: * rake (= 0.8.7) FAILED: http://devcenter.heroku.com/articles/bundler ! Heroku push rejected, failed to install gems via Bundler error: hooks/pre-receive exited with error code 1 To git@heroku.com:my_app.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'git@heroku.com:my_app.git' 

我的gemfile通常在Heroku上正常工作。 我该怎么办?

把这个放在你的Rakefile 上面需要'rake':

 require 'rake/dsl_definition' 

任何时候你改变你的Gemfile,你都需要bundle install来更新你的锁文件(Gemfile.lock)。 你推动的错误不是特定于更改耙的版本。

 bundle install git commit -a -m "update lockfile" git push heroku master 

请注意您收到的错误消息:

您在开发中修改了Gemfile,但没有将生成的快照(Gemfile.lock)检入版本控制

最后我解决了这个问题。 我所做的简短的版本,错过了许多实验,是这样的:

1)更改Gemfile以指定Rake 0.8.7

 #in Gemfile gem "rake", "0.8.7" 

2)拿出一个基于堆栈溢出问题Ruby on Rails和Rake问题之前添加到Rakefile的黑客:未初始化的常量Rake :: DSL

所以,我的Rakefile现在回到了我的应用程序的标准Rakefile:

 # 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__) require 'rake' MyApp::Application.load_tasks 

3)改变Heroku在Ruby 1.9.2中运行我的应用程序:

 heroku stack:migrate bamboo-mri-1.9.2 --app myapp git push heroku master 

现在看起来好了 – 预定的cron任务正在运行。

编辑:它运行良好,一次,然后再次炸毁下次我推了东西! Arrgh。 我想我现在修好了,增加了delayed_job gem,基于对话不知道如何构build任务工作:工作

安装delayed_job似乎不是一个很好的解决scheme,但它已经工作了,我可能想用它,特别是在Heroku每小时一次的cron工作中(这个工作不够频繁 – 有些事情我可能要每五分钟运行一次)。 在我安装了delayed_job gem后,我不得不为它做了设置,否则Heroku抱怨缺less的delayed_jobs表:

 #add to gemfile gem 'delayed_job' #at command line bundle install rails g delayed_job rake db:migrate git add -A git commit -a -m "added delayed_job gem" git push heroku rake db:migrate --app myapp heroku restart --app myapp 

我有一个Rails 3.0.11应用程序,它在Gemfile中指定Rake版本0.8.7来解决版本0.9.2 Rake :: DSL问题。

在将应用程序转换为Rails 3.2.0(Heroku Cedar堆栈)之后,我遇到了一个工作(rake任务)崩溃的问题。 我把“gem'rake','0.8.7'”改为捆绑了rake 0.9.2.2版本的“gem'rake'”。 工人停止了与新版本的崩溃。

你的问题是由于没有删除Gemfile.lock文件,并不是特定于Heroku。 删除Gemfile.lock应该可以解决这个问题,但会直接导致另一个:

 To git@heroku.com:tailored-landing-pages.git * [new branch] master -> master manfred@painstation2:~/Desktop/projects/ror/ta/tlp307$ heroku rake db:migrate rake aborted! ninitialized constant Rake::DSL /app/Rakefile:13:in `<class:Application>' /app/Rakefile:12:in `<module:Tlp307>' /app/Rakefile:11:in `<top (required)>' /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `load' /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile' /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile' /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling' /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile' /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1991:in `run' /usr/ruby1.9.2/bin/rake:31:in `<main>' 

不幸的是,我还没有find解决这个问题的办法,因为把Rake降为0.8.7在这里似乎不起作用。 如果别人有答案,我将非常感激。