How to fix the uninitialized constant Rake::DSL problem on Heroku? How to fix the uninitialized constant Rake::DSL problem on Heroku? heroku heroku

How to fix the uninitialized constant Rake::DSL problem on Heroku?


Put this in your Rakefile above require 'rake':

require 'rake/dsl_definition'


Any time you change your Gemfile, you need to bundle install to update your lockfile (Gemfile.lock). The error you're getting on push is not specific to changing the version of rake.

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

Note the error message you received:

You have modified your Gemfile in development but did not check the resulting snapshot (Gemfile.lock) into version control


I solved this, finally, after a lot of mucking about. The short version of what I did, missing out the many experiments, was this:

1) change the Gemfile to specify Rake 0.8.7

#in Gemfilegem "rake", "0.8.7"

2) Take out a hack that I had previously added to Rakefile based on Stack Overflow question Ruby on Rails and Rake problems: uninitialized constant Rake::DSL:

So, my Rakefile is now back to being the standard Rakefile for my app:

# 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) Change Heroku to run my app in Ruby 1.9.2:

heroku stack:migrate bamboo-mri-1.9.2 --app myappgit push heroku master

And it seems fine now - the scheduled cron task is running anyway.

EDIT: It did run fine, once, then blew up again next time I pushed something! Arrgh. I think I fixed it now, with the addition of the delayed_job gem, based on the conversation Don't know how to build task jobs:work.

Installing delayed_job doesn't seem like a great solution, but it HAS worked, and I might want to use it sometime I guess, especially with Heroku's once-per-hour cron job (which just isn't frequent enough - there are things I'll probably want to run every five minutes). After I installed the delayed_job gem I had to do the setup for it, otherwise Heroku complains about the missing delayed_jobs table:

#add to gemfilegem 'delayed_job'#at command linebundle installrails g delayed_jobrake db:migrategit add -Agit commit -a -m "added delayed_job gem"git pushheroku rake db:migrate --app myappheroku restart --app myapp