[英]NameError: uninitialized constant custom job file Rails 6
I have a file app/jobs/foo_bar_job.rb with the following:我有一个文件app/jobs/foo_bar_job.rb包含以下内容:
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
我运行
rails c
打开 rails 控制台,当我输入FooBarJob
时得到以下信息
NameError: uninitialized constant FooBarJob
NameError:未初始化的常量 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:
我还尝试将以下内容放入config/application.rb但它也没有修复它:
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.我正在使用 vagrant 在我的主机上运行 linux VM,在我的主机上我使用的是 rubymine。
The rails app lives within a shared directory between the host and vagrant vm. rails 应用程序位于主机和 vagrant vm 之间的共享目录中。
For whatever reason: running rails c
was not picking up the existence of that job file.无论出于何种原因:运行
rails c
没有发现该作业文件的存在。 Once I rebooted the vm: it worked as expected.一旦我重新启动了虚拟机:它按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.