我试图将Rails 5升级到6。我已经完成了升级步骤,包括添加以下内容:
# config/application.rb
config.load_defaults 6.0
我有这个类:
# lib/notification/auto_thank.rb
module Notification
class AutoThank
def perform
# stuff
end
end
end
用于任务中的:
namespace :notify do
task auto_thank: :environment do
Notification::AutoThank.new.perform
end
end
当我运行
puts config.autoload_paths
时,我的目标是让它自动加载:/my/app/path/lib/notification/auto_thank.rb
,但当我运行任务时,我会遇到一个错误:NameError: uninitialized constant Notification
。更奇怪的是,当我在任务中添加require
后,情况变得更糟了。task auto_thank: :environment do
require '/my/app/path/lib/notification/auto_thank.rb'
Notification::AutoThank.new.perform
end
我收到了一个不同的错误:
NameError: 预期文件/my/app/path/lib/notification/auto_thank.rb定义常量AutoThank,但没有定义
我缺少什么?
app/
目录下。旧的lib/
方法很快就会被弃用,并且存在问题(参见:https://dev59.com/_1oT5IYBdhLWcg3wxxok)。 - tadman