我的應用程序有lib/project/errors
其中包含了一些異常類,其中之一是ServiceException導軌 - 包括含有類模塊爲未初始化的常量錯誤
module Project
module Errors
class ServiceException < Exception
def initialize(message = nil)
super message
end
end
end
end
我想在我的GameService使用這個的:
module GameMan
class GameService
Blah blah
def validate(score)
raise Project::Errors::ServiceException.new('blah')
end
end
end
This works, 但是我討厭寫滿的模塊路徑無處不在。有沒有辦法避免這種情況?
我已經試過
module GameMan
class GameService
include Project::Errors
Blah blah
def validate(score)
raise ServiceException.new('blah')
end
end
end
這給 uninitialized constant ServiceException
錯誤。
我 config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/services)
already set in
application.rb``
我在做什麼錯?