浙江省高等学校教师教育理论培训

微信搜索“教师资格证岗前培训”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Rails 3 Quicktip: Autoload lib directory including all subdirectories, avoid lazy loading

Posted on September 22, 2010

Rails 3 doesn’t autoload files under the lib directory anymore (aka lazy loading). There was quite a discussion about this controversial decision, while lazy loading can be very good and useful, it is also convenient to not have to include every file/folder manually. Fortunately, there is an easy way to enable autoloading again. While most solutions on the Internet only show how to load one directory, here is a solution thatautoloads lib including all subdirectories on startup.
Put this in config/application.rb:

# application.rb

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]

posted on 2010-12-04 10:01  lexus  阅读(283)  评论(0编辑  收藏  举报