Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

lib/ files not autoloaded anymore

#5018

I used to be able to get files under lib/ loaded automatically, by referencing the name of the class / module defined in them. This is no longer true in Rails 3 edge, and I believe it's also not true in Beta 4.

To reproduce, create a new application, scaffold a blank class (e.g. rails g scaffold boom), then add the following file:

lib/user_filters.rb

module UserFilters
end

Modify app/controllers/application_controller.rb as follows:

class ApplicationController < ActionController::Base
  protect_from_forgery
  include UserFilters
end

Start the server, and go to http://localhost:3000/booms. The result is a routing error caused by an uninitialized constant exception.

Started GET "/booms" for 127.0.0.1 at Wed Jun 30 07:12:56 -0400 2010
ActionController::RoutingError (uninitialized constant ApplicationController::UserFilters):
  app/controllers/application_controller.rb:3
  app/controllers/booms_controller.rb:1

The code will work if I add a require to app/controllers/application_controller.rb:

require 'user_filters'

If this is an intended change, it would be nice to have it documented in the release notes. Is there some other convention to follow to get the autoloading behavior?

Thank you.

Reported by Victor Costan · June 30th, 2010 @ 01:37 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. José Valim
    José Valim
    • State changed from new to invalid
    • Importance changed from to Low

    It was intentional and it will be documented in the release notes when we do a release. To add the behavior back, just add your lib directory to config.autoload_path in config/application.rb.

    June 30th, 2010 @ 03:56 PM