在lib/
下我有'aisis_writer / loader.rb',在该文件中,它看起来像:
module AisisWriter
module Loader
end
end
然后我在我的application.rb
以下设置:
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module AisisWriter
class Application < Rails::Application
# Load Lib
config.autoload_paths += %W(#{config.root}/lib)
# Use Rack Attack For Throttling
config.middleware.use Rack::Attack
end
end
从那里我做了ApplicationController.rb
:include AisisWriter::Loader
,然后我运行了测试并得到了:
'<class:ApplicationController>': uninitialized constant AisisWriter::Loader (NameError)
由于命名冲突或我做错了,我无法做我正在做的事情。任何人都想告诉我,我可能做错了什么?
答案 0 :(得分:0)
我认为你的config.autoload_paths
不够广泛 - 它不包括lib目录的子文件。
这应该可以解决问题:
config.autoload_paths += Dir[Rails.root.join('lib', '{**/}')]
答案 1 :(得分:-1)
在&#39; aisis_writer / loader.rb&#39;
中尝试这样定义module AisisWriter::Loader
end