Search code examples
ruby-on-railsdelayed-job

rake jobs:work error, uninitialized constant


i am using delayed_job 2.1.0.pre2, and in my lib i have a class which named MailingJob(mailing_job.rb),and it has one method named perform. In my controller , i put a new MailingJob object in my delayed_job queue as the doc said. but when i run the "rake jobs:work" command,it always told me that it can't find "MailingJob", is it necessary to require the mailing_job.rb file?if yes,where should i put this? thanks!


Solution

  • mailing_job.rb must be in a place where Rails can find and auto-load it. Where do you have that file? Unless it's in app/models or something like that, it won't find it on its own.

    I have my jobs in app/jobs but this works because I added that path to the Rails load paths in the environment.rb Rails::Initializer.run block:

    config.load_paths << "#{Rails.root}/app/jobs"