草庐IT

autoload

全部标签

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

我有一个放在lib/network中的类:moduleNetworkApiclassNetworkProxyendend然后在另一个类中,我引用了这个类:network_proxy=::NetworkApi::NetworkProxy.new(params)一切都在我的开发环境中正常运行,但是当我部署到服务器时,我在上面一行收到错误消息:NameError:uninitializedconstantNetworkApi::NetworkProxy我不知道为什么会出现这个奇怪的错误。请告诉我为什么。 最佳答案 请注意Rails5dis

ruby - 使用 autoload 与 ruby​​ 中的 require 进行惰性评估?

在我的代码中,我使用自动加载进行惰性评估,这样我可以更快地加载程序并在需要时加载文件,我没有看到很多人使用它,但在Thin项目中我注意到自动加载已被广泛使用,反正只是想知道使用它是否有任何风险。 最佳答案 autoload是notthreadsafe并将在未来的Ruby版本中弃用。这是proofbyMatz(ruby的创造者)。 关于ruby-使用autoload与ruby​​中的require进行惰性评估?,我们在StackOverflow上找到一个类似的问题:

ruby-on-rails - rails 5 : Autoloading with custom folders not working

我有这门课:#app/events/new_request.rbclassEvents::NewRequestend然后我将该文件夹添加到自动加载:#config/application.rbconfig.autoload_paths+=%W(events/)当运行railsc时:>Events::NewRequestNameError:uninitializedconstantEvents问题是,如果我在定义类时不使用命名空间“Events”,它会成功自动加载类。 最佳答案 moduleSandboxclassApplicatio

Ruby:自动加载方法有什么作用?

moduleActionControllerextendActiveSupport::Autoloadautoload:Baseautoload:Cachingautoload:Metalautoload:Middlewareend任何人都可以用示例/样本输出详细说明自动加载方法的作用吗? 最佳答案 Autoload确保在需要时自动加载类或模块。PeterCooper有一篇不错的文章,名为"RubyTechniquesRevealed:Autoload"这解释了需要的差异。我不想在这里重复他的例子:-)

ruby-on-rails - 命名空间模块和 Rails 3.1.3 autoload_path

我在为包含在模型中的模块命名空间时遇到了一些麻烦。在/app/models/car.rb中classCarincludeSearch::Carend在/lib/search/car.rb中moduleSearchmoduleCarincludeActiveSupport::Concern#methodsinhereendend在/config/application.rb中config.autoload_paths+=Dir["#{config.root}/lib/**/"]config.autoload_paths+=Dir["#{config.root}/lib/search/*"

ruby - 运行时错误 : Circular dependency detected while autoloading constant

我通过引入请求和响应模型来重构我的Controller,以执行此presentation之后Controller周围的一些逻辑。.我分别用模块Responses和Requests包装了所有的响应和请求模型。应用程序运行完美,但当我运行测试时,出现以下错误。Failure/Error:UnabletofindmatchinglinefrombacktraceRuntimeError:CirculardependencydetectedwhileautoloadingconstantResponses::FolderContentResponse我的目录结构如下:-应用/-模型/-回应/注

ruby-on-rails - Controller : Circular dependency detected while autoloading constant 中的 Rails 4 运行时错误

如果我遗漏了什么,请告诉我。我不明白为什么无法访问我的views/references/文件夹。new.html.erb和index.html.erb都不可用。当我转到localhost:3000/references时,我的错误是:RuntimeErrorinReferencesController#indexCirculardependencydetectedwhileautoloadingconstantReferencesController我相信这是设置,它不应该是Rails问题,因为我的其他Controller工作正常。我的路线文件中有resources:reference

ruby-on-rails - 为什么都是autoload,load_all!并要求全部用于 active_support.rb?

我正在查看active_support.rb以尝试了解它使用的加载过程。它使用三种加载方法:load_all!、autoload和require。为什么在同一个文件中使用三种不同的加载方式?moduleActiveSupportdefself.load_all![Dependencies,Deprecation,Gzip,MessageVerifier,Multibyte,SecureRandom,TimeWithZone]endautoload:BacktraceCleaner,'active_support/backtrace_cleaner'autoload:Base64,'ac

ruby-on-rails - Rails 中的多线程 : Circular dependency detected while autoloading constant

我有一个Rails应用程序,其中有一个Rake任务,该任务使用并发rubygem提供的多线程函数。有时我会遇到Circulardependencydetectedwhileautoloadingconstant错误。在谷歌搜索了一下后,我发现这与结合使用线程和加载Rails常量有关。我偶然发现了以下GitHub问题:https://github.com/ruby-concurrency/concurrent-ruby/issues/585和https://github.com/rails/rails/issues/26847如此处所述,您需要将从新线程调用的所有代码包装在Rails.a

ruby - 随着 'autoload' 被弃用,开发者应该同时使用什么?

几周前读到autoload是officiallydeprecated,Matz不鼓励使用它。用什么来代替它?开发人员应该怎么做?我在一些命令行gem中使用它来避免不必要地加载可能永远不会使用的库,并在JRuby中使用它来防止对.jar文件进行相同的加载。 最佳答案 我见过人们使用EasyLoadgem,它声称是一个autoload替代品。它根据目录模块命名约定加载。 关于ruby-随着'autoload'被弃用,开发者应该同时使用什么?,我们在StackOverflow上找到一个类似的问