Rails 库包括 [英] Rails lib includes

查看:14
本文介绍了Rails 库包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 lib 目录中定义的模块的令人费解的问题

I have a puzzling issue regarding modules defined in the lib dir

我有两个文件

#lib/authentication.rb

module Authentication

end


#lib/test_module.rb

module TestModule

end

在我的应用程序控制器中

In my application controller I have

 class ApplicationController < ActionController::Base
     include Authentication
     include TestModule
 end

身份验证模块正确加载,但 TestModule 没有

The Authentication Module loads properly but the TestModule does not

我得到未初始化的常量 ApplicationController::TestModule"

I get "uninitialized constant ApplicationController::TestModule"

我被难住了……有人吗?

I am stumped... anyone?

有人知道我可以在哪里调试吗?

Does anyone know where I could look to debug this?

推荐答案

在 ApplicationController 文件的顶部添加 require 'lib/test_module' 可能会有所帮助

Adding require 'lib/test_module' at the top of your ApplicationController file might help

这篇关于Rails 库包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆