如何在Heroku上修复未初始化的常量Rake :: DSL问题?

ben*_*ben 101 rake ruby-on-rails heroku ruby-on-rails-3

我越来越类似于那些错误 这些 问题,除了我的是上发生的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>'
Run Code Online (Sandbox Code Playgroud)

这些问题的答案似乎是要指定,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'
Run Code Online (Sandbox Code Playgroud)

我的gemfile通常在Heroku上运行正常.我该怎么办?

小智 205

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

require 'rake/dsl_definition'
Run Code Online (Sandbox Code Playgroud)

  • 该死的,这比我的解决方案简单得多!:/ (3认同)
  • 谢谢.这解决了我的问题,我不知道发生了什么.(在Windows上使用rails安装程序并部署到heroku,作为一个完整的初学者.) (3认同)
  • 我得到了错误部署到Heroku的错误,Heroku今天的收益率为0.9.2.由于最初的问题是0.9.0,也许rake版本不再是问题.将`require`行添加到rakefile(并重新启动并重新推送到github和Heroku)解决了它.@David,我使用的是带有RailInstaller 1.2.0的RoR框架的Windows. (2认同)

wup*_*tah 8

每次更改Gemfile时,都需要bundle install更新锁文件(Gemfile.lock).您推送的错误并非特定于更改rake的版本.

bundle install
git commit -a -m "update lockfile"
git push heroku master
Run Code Online (Sandbox Code Playgroud)

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

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


Max*_*ams 6

经过大量的捣乱,我终于解决了这个问题.我所做的简短版本,错过了许多实验,是:

1)更改Gemfile以指定Rake 0.8.7

#in Gemfile
gem "rake", "0.8.7"
Run Code Online (Sandbox Code Playgroud)

2)根据Stack Overflow问题Ruby on Rails和Rake问题,取出我之前添加到Rakefile的hack :未初始化的常量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
Run Code Online (Sandbox Code Playgroud)

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

heroku stack:migrate bamboo-mri-1.9.2 --app myapp
git push heroku master
Run Code Online (Sandbox Code Playgroud)

现在看起来很好 - 无论如何,预定的cron任务正在运行.

编辑:它确实运行良好,一次,然后在我推动东西时再次爆炸!Arrgh.我想我现在修复了它,添加了delayed_jobgem,基于对话不知道如何构建任务工作:工作.

安装delayed_job似乎不是一个很好的解决方案,但它已经工作了,我可能想在某些时候使用它,特别是Heroku的每小时一次的cron工作(这是不够频繁的 - 有些东西我'我可能想每五分钟跑一次).在我安装了delayed_jobgem后,我必须为它进行设置,否则Heroku会抱怨丢失的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
Run Code Online (Sandbox Code Playgroud)