Craig Walker
Craig Walker

Reputation: 51727

application_controller.rb not being loaded

In my Rails app (running on rails 2.3.5, ruby 1.8.7), my application_controller.rb file is not being loaded automatically when config.cache_classes = false in environment.rb.

It's in the load path. If I add require 'application_controller' to the end of my environment.rb or set cache_classes = true, then the app works fine.

Why wouldn't it load when classes are not being cacehed?

Upvotes: 0

Views: 913

Answers (4)

Ben Lee
Ben Lee

Reputation: 53319

This sounds like it for some reason your app is still using 2.3.2 gems for ActiveSupport. It is probably still looking for application.rb, and the undefined pretty_inspect also lends itself to a versioning problem.

First, make sure that you don't have something like this at the top of your environment.rb:

RAILS_GEM_VERSION = '2.3.2'

If you don't, then at the bottom of the your environment.rb find out if something else is setting it wrong by adding this:

puts RAILS_GEM_VERSION

Upvotes: 1

Ben Lee
Ben Lee

Reputation: 53319

I have another idea. You mentioned that it is in the load path, but I would confirm later on that it stays in the load path and that a plugin doesn't mess it up or something. At the very bottom of environment.rb (last line) add this line:

puts ActiveSupport::Dependencies.load_paths.pretty_inspect

Then run a script/server from the command line and take a look at the load paths, making sure /path_to_your_rails_app/app/controllers shows up.

Upvotes: 1

Ben Lee
Ben Lee

Reputation: 53319

The application code is loaded as part of the Rails::Initializer.run method in environment.rb. It's almost the last step. I know of nothing that would prevent the application controller from loading -- my only suggestion is to make sure there is not a typo in the filename /app/controllers/application_controller.rb and to make sure there is not a typo in the class definition class ApplicationController < ActionController::Base.

I'd like to add that the first part my last comment applies to production mode, where the classes are eager-loaded in Rails::Initializer#load_application_classes, but in development mode it does not cache classes, so loads them as part of a const_missing catcher each request. See ActiveSupport::Dependencies#load_missing_constant.

Upvotes: 1

Craig Walker
Craig Walker

Reputation: 51727

The problem is definitely related to config.cache_classes = false; if I switch this to true then the problem disappears.

(Thanks @Ben Lee for leading me towards this)

Upvotes: 0

Related Questions