gpt4 book ai didi

ruby-on-rails - rails : uninitialized constant just happen on production server

转载 作者:数据小太阳 更新时间:2023-10-29 07:11:26 31 4
gpt4 key购买 nike

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

module NetworkApi
class NetworkProxy
end
end

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

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

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

NameError: uninitialized constant NetworkApi::NetworkProxy

我不知道为什么会出现这个奇怪的错误。请告诉我为什么。

最佳答案

请注意 Rails 5 disables autoloading after booting the app in production .

来自链接的博客文章:

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')`

关于ruby-on-rails - rails : uninitialized constant just happen on production server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41560160/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com