Expected .. to define

That means it's loading application.rb looking for an Application
class, but app/controllers/application.rb defines
ApplicationController. For some reason it's being loaded ahead of
lib/ and app/models. You may have to require your application class
manually or rename it.

Actually, for some reason it happens sometime (not only with
ApplicationController). See
http://dev.rubyonrails.org/ticket/7452 for example.

I had an application that suddenly blowed up in that way after a small
upgrade (in production mode) -- just a dummy html change in a view. I
had to start - stop my app several times for it to load properly (see
the note of saizai for example on the ticket 7452).

That's really weird (bug constated with Rails 1.2.2 & 1.2.3 with several
applications).

I began running into this problem tonight. The strange thing is that
I have the same codebase (from Subversion) installed on several
different sites. All but one work okay.

After digging around for quite a while, I noticed on one of my SVN UP
commands, my controller (the one causing me problems) had a conflict
which I hadn't noticed before.

When I looked in the controllers directory, I found that my controller
was there but it had all kinds of merged code in it. I deleted all of
the controllers and the various SVN versions and restored the
controller from the repository. Voila... we're working again.

Cheers.

MCN

Hello,

I wanted to chime in because I had a similar proble, Expected /
.../app/controllers/application.rb to define Application. On production
only. Rails 2.1.2, apache2, passenger. This thread was helpful and I
found in my stack trace the noted const_missing, originating at line 90
in one of my classes, permission.rb

<pre>
vendor/rails/activesupport/lib/active_support/dependencies.rb:484:in
`const_missing'
app/models/permission.rb:90:in `initialize_project'
</pre>

The method in question had a case statement like so:

<pre>
@project ||= case @resource
      when Project
        @resource
      ....
end
</pre>

It was crapping out on line 90, which was:
<pre>
when Project
</pre>

I tried giving it an absolute path to Project, like so:
<pre>
@project ||= case @resource
      when ::Project
        @resource
      ....
end
</pre>

And this solved the problem.

Hopefully that helps someone as this thread helped me.

sg

Let me just add that while what I wrote above did work a few times, the
problem recurred. So I would not say that is a good solution. At this
point I manually required my classes in the other class:

require 'project'
require 'asset'
...

and this seems to work. It is a mystery to me, but hope someone else
is helped.

sg.

Sarah Gray wrote:

I also had the same problem. My application is running rails 2.0.2.
Has anyone actually found a good solution for this?

I also had the same problem. My application is running rails 2.0.2.
Has anyone actually found a good solution for this?

The error message is misleading. Expected foo.rb to define Foo usually
just means that something bad happened when loading foo.rb (syntax
errors, missing constant etc...). You can usually get a better error
message by just typing Foo into script/console

Fred

I also had the same problem. My application is running rails 2.0.2.
Has anyone actually found a good solution for this?

Hope this helps someone who is in the same boat.

If you have a controller named ApplicationsController (there is
additional 's' in the controller name) and also the corresponding
model Application, Rails is trying to load the wrong Application.rb
file which is why we are encountering the following message.

"Expected /.../app/controllers/application.rb to define Application."

Instead of loading app/models/application.rb, it is loading app/
controllers/application.rb which is the base controller from which the
other controllers inherit, and not surprisingly it is not able to find
the Class definition of Application (it is actually defined in app/
models/application.rb)

I solved this by renaming the app/controllers/application.rb to app/
controllers/application_controller.rb and everything works as
expected.

-Satynos

Hope this helps someone who is in the same boat.

When you have controller named ApplicationsController and an
associated model named Application, Rails is loading the wrong
application.rb file and producing the following error. It is loading
the app/controllers/application.rb file instead of app/models/
application.rb when you instantiate Application object.

Expected /
.../app/controllers/application.rb to define Application.

Instead when you rename the app/controllers/application.rb (base
controller) to app/controllers/application_controller.rb, everything
works as expected.

-Satynos