Rails:未初始化的常量只发生在生产服务器上 [英] Rails: uninitialized constant just happen on production server

查看:29
本文介绍了Rails:未初始化的常量只发生在生产服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个放在 lib/network 中的类:

I have a class that I put inside lib/network:

module NetworkApi
  class NetworkProxy
  end
end

然后在另一个类中,我引用了这个类:

Then in another class, I referenced this class:

  network_proxy = ::NetworkApi::NetworkProxy.new(params)

一切都在我的开发环境中正常运行,但是当我部署到服务器时,我在上面的行中收到错误消息:

Everything runs normally on my development environment, but when I deploy to the server, I get an error at the above line with the message:

NameError: uninitialized constant NetworkApi::NetworkProxy

我不知道为什么会发生这个奇怪的错误.请告诉我原因.

I don't know why this strange error happens. Please tell me why.

推荐答案

注意 Rails 5 在生产环境中启动应用程序后禁用自动加载.

来自链接的博客文章:

在我们的应用程序在生产环境中仍然需要自动加载的罕见情况下,我们可以通过将enable_dependency_loading设置为true来启用它,如下所示:

In the rare situation where our application still needs autoloading in the production environment, we can enable it by setting up enable_dependency_loading to true as follows:

# config/application.rb 

config.enable_dependency_loading = true
config.autoload_paths << Rails.root.join('lib')`

这篇关于Rails:未初始化的常量只发生在生产服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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