Search code examples
ruby-on-railsruby-on-rails-3delayed-job

uninitialized constant Delayed::Job


I've added the delayed_job gem to my gemfile and installed correctly but when I try to run the following line:

Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc

I get the error 'uninitialized constant Delayed::Job'

Can somebody explain what i need to do here? I've tried running 'rake jobs:work' beforehand but it also returns the 'uninitialized constant Delayed::Job' error. Additionally, I've added "require 'delayed_job'" to the file (application.rb) without much luck.


Solution

  • Did you follow the installation instructions on the README file? https://github.com/collectiveidea/delayed_job

    Add this to your gemfile:

    gem 'delayed_job_active_record'
    

    and then run this at the console:

    $ rails generate delayed_job:active_record
    $ rake db:migrate
    

    You need to create the delayed jobs table in the database (this assumes you're using active record).

    For Rails 3, all you need to do is include it in the gemfile, run that code above to create the table and migrate the database, then restart your server and go!