我正在使用Ruby on Rails5。我已经在lib / audit / top_level_service.rb中创建了此基类
module Audit::Services
class TopLevelService
...
end
end
在我的应用程序的另一部分,app / services / accounting_service.rb中,我想从上面创建的这个模块继承,所以我尝试过]]
class PerkspotService < Audit::Services::TopLevelService ... end
但这会导致“未初始化的常量Audit :: Services”错误。从正常的类定义中引用我的基类的正确方法是什么?
我正在使用Ruby on Rails5。我在lib / audit / top_level_service.rb模块Audit :: Services类TopLevelService中创建了这个基类... end在我的应用程序的另一部分,app / ...] >
原因是Autoloading and Reloading Constants。当您尝试访问PerkspotService
时,它没有Audit::Services
,并且没有文件audit/services.rb
。您可以尝试多种方法来解决它。您可以像这样在application.rb
中预定义名称空间:
Audit = Module.new
Audit::Services = Module.new