gpt4 book ai didi

ruby-on-rails - 如何禁用目录的 rails 延迟加载?

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

我正在创建一组依赖于它们以特定顺序被 required() 的类,因为我在父级上使用类方法#inherited。

由于 rails 仅在类首次使用时才尝试加载类,因此父类的#inherited 方法只是有时加载,并非总是加载。

是否可以通过 Rails 方式预先加载此类?还是我应该将它们放在另一个目录中并调用“require”?

最佳答案

您可以利用可以在 environments/(development|production).rb 文件中设置的 config.eager_load_paths 属性。

config.eager_load_paths accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the app directory of the application. All elements of this array must also be in load_paths.

来自 here

关于ruby-on-rails - 如何禁用目录的 rails 延迟加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5479921/

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