Navigation Menu

Skip to content

Commit

Permalink
files in the lib directory are no longer autoloaded
Browse files Browse the repository at this point in the history
Conceptually, the lib directory is closer 3rd party libraries
than to the application itself. Thus, Rails adds it to Ruby's
load path ($LOAD_PATH, $:) but it is no longer included in
dependencies' load paths.

To enable autoloading back put this in your config/application.rb

  config.load_paths += %W( #{config.root}/lib )
  • Loading branch information
fxn committed Jun 20, 2010
1 parent 69fec3a commit b5fe014
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion railties/lib/rails/engine/configuration.rb
Expand Up @@ -20,15 +20,19 @@ def paths
paths.app.models "app/models", :eager_load => true
paths.app.mailers "app/mailers", :eager_load => true
paths.app.views "app/views"
paths.lib "lib", :load_path => true

paths.lib "lib"
paths.lib.tasks "lib/tasks", :glob => "**/*.rake"

paths.config "config"
paths.config.initializers "config/initializers", :glob => "**/*.rb"
paths.config.locales "config/locales", :glob => "*.{rb,yml}"
paths.config.routes "config/routes.rb"

paths.public "public"
paths.public.javascripts "public/javascripts"
paths.public.stylesheets "public/stylesheets"

paths
end
end
Expand Down
4 changes: 3 additions & 1 deletion railties/test/application/initializers/load_path_test.rb
Expand Up @@ -19,7 +19,7 @@ def setup
assert $:.include?("#{app_path}/app/models")
end

test "initializing an application allows to load code on lib path inside application class definitation" do
test "initializing an application allows to load code on lib path inside application class definition" do
app_file "lib/foo.rb", <<-RUBY
module Foo; end
RUBY
Expand Down Expand Up @@ -60,6 +60,8 @@ module Zoo::ReptileHouse ; end

add_to_config <<-RUBY
config.root = "#{app_path}"
config.cache_classes = true
config.load_paths << "#{app_path}/lib"
config.eager_load_paths << "#{app_path}/lib"
RUBY

Expand Down

3 comments on commit b5fe014

@aaronchi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break the loading of plugins

@fxn
Copy link
Member Author

@fxn fxn commented on b5fe014 Jun 20, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it needs more thought, it is reverted now b311dbb

@augustl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thing it's reverted. lib/app_name/foo.rb with AppName:: Foo is pretty common.

Please sign in to comment.