Topic: Weird error trying to define controller?

I cannot figure out why I'm getting this error in production on a CentOS server. Tell me what you think:

LoadError (Expected /home/www/cococms/config/../app/controllers/account_controller.rb to define AccountController):
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in `load_missing_constant'
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing'
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:464:in `const_missing'
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/inflector.rb:250:in `constantize'
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/string/inflections.rb:148:in `constantize'
    /vendor/rails/actionpack/lib/action_controller/routing.rb:1276:in `recognize'
    /vendor/rails/railties/lib/dispatcher.rb:38:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
    /usr/local/bin/mongrel_rails:16


Rendering /home/www/cococms/config/../public/500.html (500 Internal Server Error)


Here's the error I get in console when trying to use the AccountController object:

NoMethodError: undefined method `is_missing?' for #<LoadError:0xb7a19cb4>
        from ./script/../config/../config/../vendor/rails/actionpack/lib/action_controller/helpers.rb:114:in `default_helper_module!'
        from ./script/../config/../config/../vendor/rails/actionpack/lib/action_controller/helpers.rb:126:in `inherited_without_api'
        from ./script/../config/../config/../vendor/rails/actionwebservice/lib/action_web_service/container/action_controller_container.rb:84:in `inherited_without_action_controller'
        from ./script/../config/../config/../vendor/rails/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb:32:in `inherited'
        from ./script/../config/../config/../app/controllers/account_controller.rb:1
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:495:in `require'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:495:in `require'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:104:in `require_or_load'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:248:in `load_missing_constant'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:464:in `const_missing'
        from (irb):1

And then a different error after that:

LoadError: Expected script/../config/../config/../app/controllers/account_controller.rb to define AccountController
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in `load_missing_constant'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:464:in `const_missing'
        from (irb):2

The problem goes away after I unfreeze edge rails, but then my app does not work properly.

Last edited by wesr (2007-01-30 12:24:18)

Re: Weird error trying to define controller?

Can you post your account_controller.rb file?

Railscasts - Free Ruby on Rails Screencasts

Re: Weird error trying to define controller?

I've removed all code from my AccountController, and I still get the same error.

Last edited by wesr (2007-01-30 12:17:03)

Re: Weird error trying to define controller?

Don't remove all the code, Rails expects at least this:

class AccountController < ApplicationController
 
end

If that doesn't exist, that is why you are getting the error.

Railscasts - Free Ruby on Rails Screencasts

Re: Weird error trying to define controller?

Sorry, I meant to say I removed all code inside of the class definition.

Re: Weird error trying to define controller?

Hmm, and the class definition looks exactly like that? Same uppercase/lowercase and everything? And this script exists at "app/controllers/account_controller.rb"?

See if restarting the server fixes it - maybe the loading script kind of got off track.

Railscasts - Free Ruby on Rails Screencasts

Re: Weird error trying to define controller?

Yes, the class definition is as follows:

class AccountController < ApplicationController
end

Restarting doesn't help, unfortunately. All other controllers work fine except for my AccountController. Unfreezing rails helps, but then my app doesn't work like it should. The development version (local) works fine with edge rails.

Re: Weird error trying to define controller?

Strange, my last guess is it is something to do with how the document is formatted - perhaps the line endings are different and Ruby is having trouble parsing it.

You may want to try removing the file entirely, copying over one that works and editing that.

Perhaps someone else has an idea of what is wrong.

Railscasts - Free Ruby on Rails Screencasts

Re: Weird error trying to define controller?

Try running it under webrick rather than mongrel:

ruby script/server webrick

I've encountered this error several times lately and it's always had to do with my server caching the files.  Though I can't understand why it wouldn't work in the console (except that the console also caches files).

If it works with rails unfrozen (i.e. floating off gems) then it's not so much a problem with your app as it is with some sort of cache (I think).

Re: Weird error trying to define controller?

Running webrick instead of mongrel produced the same errors. I'm under the impression that it's just a problem with edge rails. I reverted to revision 6045. This has temporarily fixed my problem. Thanks for the advice everyone.

Re: Weird error trying to define controller?

This seems to relate to http://railsforum.com/viewtopic.php?pid=13056#p13056

Last edited by 4lex (2007-02-11 10:14:23)

Re: Weird error trying to define controller?

I seem to be having this same error with just one of my controllers.  I've just run my functional test and I'm getting the error there as well as through Mongrel so it doesn't appear to be server related.

I've tried creating a new and empty controller of the same name and I still get the error.

The controller I'm having trouble with is as follows:

class UsersController < ApplicationController
  verify :method => :post, :only => [:destroy, :create, :update], :redirect_to => {:action => :list}
  before_filter :login_required, :except => ['new', 'create']

  def index
  #this will be the "home page" or profile for the user.  For now we will redirect to the main controller
    redirect_to :controller => 'main'
  end

  def list
  #this will serve as a place for admin to view information on various users
    @users = User.find(:all, :order => 'username')   
  end

  def new
    @user = User.new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(params[:contact])
    @user = @contact.tasks.build(params[:user])
    if @contact.save
      session[:user] = User.authenticate(@user.login, @user.password)
      flash[:notice] = "Signup Successful"
      redirect_to :controller => 'contact', :action => 'show', :id => @contact
    else
      flash[:warning] = "Signup unsuccessful"
      render :action => 'new'
    end
  end

  def edit
    @user = User.find(params[:id])
    @contact = @user.contact   
  end

  def update
    @user = User.find(params[:id])
    @contact = @user.contact
    if @user.update_attributes(params[:user]) && @contact.update_attributes(params[:contact])
      flash[:notice] = "User account has been saved successfully"
      redirect_to :controller => 'contact', :action => 'show', :id => @contact
    else
      render :action => 'edit', :id => @user
    end
  end

  def destroy
    @user = User.find(params[:id])
    @contact = @user.contact
    @user.destroy
    redirect_to :controller => 'contact', :action => 'show', :id => @contact
  end
end


It's claiming the error is in line 1 of the controller so I don't actually think the rest of the code is relevant.  (I'd provide the stack trace but I can't copy and paste from the damn Windows console).

I don't see how it can be a problem with my ApplicationController seeing as all my other controllers are working fine, but here's the code just in case (most of it's commented out at the moment because I haven't set up logins yet).

class ApplicationController < ActionController::Base
  layout "base"
  filter_parameter_logging "password"
 
  def login_required
    #if session[:user_id]
      return true
    #end
    #flash[:warning]="Please login to continue"
    #redirect_to :controller => 'login', :action => 'new'
    #return false
  end

  def current_user
    #@current_user = User.find(session[:user_id])
    @current_user = User.find(1)
  end
 
  def admin_required
    user_id = session[:user_id]
    user = User.find(user_id)
    if user.type == "admin"
      return true
    end
    flash[:warning] = "You need to be a site administrator to access this functionality"
    session[:return_to] = request.request.uri
    redirect_to_stored
    return false
  end
 
  def redirect_to_stored
    if return_to = session[:return_to]
      session[:return_to] = nil
      redirect_to_url(return_to)
    else
      redirect_to :controller => 'main', :action => 'index'
    end
  end
end


If there's anything else that might be relevant then let me know and I'll try and find it out.  I'm using edge rails.

Re: Weird error trying to define controller?

I just can tell I have exactly the same problem and reported it here:
http://dev.rubyonrails.org/ticket/7452

Strange enough it seems I can build a new application whith rails which runs
However it does not matter which Web server I'm using. Unfortunatly I have not idea on how one can debug such crapp.

Regards
Friedrich

Re: Weird error trying to define controller?

Hi, I was experiencing the same problem and guess what! The problem was a wrong class name but not the Controller's one, it's of its helper, it wasn't in plural:

module UsersHelper

Hope it helps.

Re: Weird error trying to define controller?

No I don't think the problem is with the Helper File.
As I am getting the same problem and in my helper file the name of class is pluralized but i am still getting the error.

Re: Weird error trying to define controller?

I had the same problem, not sure what was causing it but, copying the code from another controller that worked, and giving the working controller the correct class name fixed it.