开发者

rake jobs:work error, uninitialized constant

i am using delayed_job 2.1.0.pre2, and in my lib i have 开发者_如何学Ca 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!


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"


Nowadays in Rails 6.1 I had to put it in the application.rb as follows:

config.autoload_paths << Rails.root.join('/app/jobs')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜