Rails 3 Quicktip: Autoload lib directory including all subdirectories, avoid lazy loadingRails 3 Quicktip: Automatisch lib Ordner und Unterordner laden

lazy cat

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 that autoloads lib including all subdirectories on startup.
Put this in config/application.rb:

lazy cat
Being lazy is good


See also our blog post, how you can force Rails 3 to reload the lib files: http://hemju.com/2011/02/11/rails-3-quicktip-auto-reload-lib-folders-in-development-mode/

In Rails 3 hat man den Mechanismus für das Laden der lib Dateien von automatisch auf manuell umgestellt (aka lazy loading). Über diese umstrittene Entscheidung gab es bereits einige Diskussionen mit den Entwickler. Lazy Loading hat oftmals Vorteile und seine Berechtigung, aber andererseits ist es auch mühsam jede Datei und Verzeichnis manuell hinzuzufügen. Glücklicherweise gibt es eine einfache Lösung um das alte Verhalten wiederherzustellen. Die meisten Lösungen im Internet zeigen nur wie man ein Verzeichnis automatisch lädt, hier ist eine die automatisch das lib Verzeichnis inklusive aller Unterverzeichnisse lädt.
Einfach folgendes in die Datei config/application.rb eintragen:

lazy cat
Faulheit hat auch gute Seiten

Author: Helmut M. Juskewycz

I like and create awesome Software! Besides developing, I am interested in a lot of things. Startups, Business, Gaming, Sports, Movies, just to name a view. Founder of LingoHub.

13 thoughts on “Rails 3 Quicktip: Autoload lib directory including all subdirectories, avoid lazy loadingRails 3 Quicktip: Automatisch lib Ordner und Unterordner laden

  1. This does not reload the classes kept under autoload_paths in dev environment. While googling I figured that one can use require_dependency to make it reloadable However, it still requires one to do it file by file. Is there a better way to make autoload_paths reloadable in dev environment.

  2. I precisely desired to thank you very much once more. I am not sure the things that I would have achieved in the absence of the type of recommendations discussed by you regarding my question. Previously it was a very alarming scenario in my position, but coming across this specialized style you resolved the issue forced me to weep for happiness. Now i’m happier for this support and thus hope you are aware of a powerful job you are always doing training men and women through your websites. I am certain you’ve never got to know all of us.

  3. Blogs are websites that enables the blogger to often add
    content with a selected topic. Blogging are often outlined because the loading
    or adding content on the journal. Remember, there’s a distinction between
    business one thing on a journal and on a daily web site. Some contemplate them
    2 platforms of opposite nature.

Leave a Reply