I have a file app/jobs/foo_bar_job.rb with the following:
class FooBarJob < ApplicationJob
queue_as :default
def perform(*args)
# Do stuff
end
end
I run rails c
to open up the rails console and I get the following when I type FooBarJob
NameError: uninitialized constant FooBarJob
My app doesn't know about the constant. I'm not sure what I am missing. I also attempted putting the following within config/application.rb but it didn't fix it either:
require_relative 'boot'
require 'rails/all'
Bundler.require(*Rails.groups)
module MyApp
class Application < Rails::Application
config.load_defaults 6.0
# I added this line to attempt to load all files within /app/jobs
config.autoload_paths += Dir[Rails.root.join('app', 'jobs', '{**}')]
end
end
This turned out to be a very environment-specific issue. I'll post my fix, but it is still a mystery.
I am using vagrant to run a linux VM on my host machine, and on my host machine I am using rubymine.
The rails app lives within a shared directory between the host and vagrant vm.
For whatever reason: running rails c
was not picking up the existence of that job file. Once I rebooted the vm: it worked as expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.