关于 lib 目录中定义的模块,我有一个令人费解的问题
我有两个文件
#lib/authentication.rb
module Authentication
end
#lib/test_module.rb
module TestModule
end
在我的应用程序控制器中我有
class ApplicationController < ActionController::Base
include Authentication
include TestModule
end
身份验证模块正确加载,但测试模块未正确加载
我得到“未初始化的常量 ApplicationController::TestModule”
我很困惑...有人吗?
编辑:有谁知道我可以在哪里调试这个?
从 Rails 3 开始,请确保添加lib
目录到config.autoload_paths
in config/application.rb
,以便读取包含模块的文件并加载模块。
config.autoload_paths += %W(#{config.root}/lib)
Look here有关此内容和加载子目录的更多信息。
Also, 据推测 "你不应该使用 require在 Rails 应用程序中,因为它会阻止 ActiveSupport::Dependencies 正确[卸载]加载该代码”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)