开发者

Load path in Rails?

开发者 https://www.devze.com 2023-01-10 19:24 出处:网络
In the Rails guides they have this code to load a path. $LOAD_PATH <开发者_高级运维< path

In the Rails guides they have this code to load a path.

  $LOAD_PATH <开发者_高级运维< path
  ActiveSupport::Dependencies.load_paths << path
  ActiveSupport::Dependencies.load_once_paths.delete(path)

The first one I understand. That is for ruby to know where to require files.

But what does the second and the third one means?


Yes, the first line is for Ruby itself (and $: too). The second one is very similar to the first one, but for ActiveSupport.

load_once_paths An array of paths from which Rails will automatically load from only once. All elements of this array must also be in load_paths.

load_paths An array of additional paths to prepend to the load path. By default, all app, lib, vendor and mock paths are included in this list.

So, if you need to reload your dependencies every new request, don't add them to the one of load_once_paths directory.


In Rails 3.0 load_once_paths has been renamed to autoload_once_paths and load_paths has been renamed to autoload_once_paths.

0

精彩评论

暂无评论...
验证码 换一张
取 消