Search code examples
ruby-on-railsautoload

Why is the lib directory in Rails not in the autoload path by default?


I know the lib/ directory can be added to the autoload_paths and eager_load_paths quite easily. But I don't quite understand why files in lib/ are not autoloaded or eager loaded by default?

I can't find a simple answer anywhere unfortunately so I'd really appreciate if someone could explain this to me simply!


Solution

  • Because there is no Rails convention for putting files in lib that require autoloading. lib is for rake/thor tasks which reside lib/tasks and little else.

    Your application-specific files should go in app. If you find yourself thinking of putting something in lib, it probably belongs somewhere in app, or in a Gem.