【问题标题】:Heroku Production: config.autoload_paths doesnt seem to workHeroku 生产:config.autoload_paths 似乎不起作用
【发布时间】:2017-05-16 15:28:09
【问题描述】:

我有一个在开发中运行良好的 Rails 应用程序。它访问我在/lib 文件夹中的一个类,因为

config.autoload_paths += Dir["#{config.root}/lib/**/"]

我的 application.rb 配置文件中的行。但是,当我在 Heroku 上运行生产环境中的应用程序时,我收到了 Uninitialized Constant 错误。

例如在本地运行rails c:

>rails c
001> OrderPdf
 => OrderPdf
002>

但在生产中:

>heroku run rails c
001> OrderPdf
NameError: uninitialized constant OrderPdf
(stack trace)
002>

这是怎么回事?

【问题讨论】:

    标签: ruby-on-rails heroku production


    【解决方案1】:

    因为在 prod 上,您的配置中可能有这一行 config.eager_load = true ,它会预先加载您的所有类。

    要解决这个问题,您添加到 autoload_path 的所有内容,也要添加到 eager_load 路径

    config.eager_load_paths += Dir["#{config.root}/lib/**/"]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      • 2016-04-06
      • 2018-04-01
      • 2015-01-23
      • 2016-11-29
      • 2016-02-01
      相关资源
      最近更新 更多