This project is archived and is in readonly mode.

#5018 ✓invalid
Victor Costan

lib/ files not autoloaded anymore

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

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.

Comments and changes to this ticket

  • José Valim

    José Valim June 30th, 2010 @ 03:56 PM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages