Rails3: Expected admin/items_controller.rb to define ItemsController
The following causes unexpected exception:
Expected app/controllers/admin/items_controller.rb
to define ItemsController
Foo::Application.routes.draw do
resources :items
match '/admin' => 'admin/overview#index', :as => :admin
namespace :admin do
res开发者_如何学Pythonources :items
end
end
% cat app/controllers/admin/items_controller.rb
class Admin::ItemsController < Admin::BaseController
end
% cat app/controllers/admin/base_controller.rb
class Admin::BaseController < ActionController::Base
% cat app/controllers/items_controller.rb
class ItemsController < ApplicationController
end
It worked for me in the Rails 2.3.5.
What might be wrong the code? How can I fix that?
I can't reproduce the error this particular time, but I have run into it in the past. From memory, there are two things you can do:
Go to the Rails console (
rails console
in your application directory) and type inItemsController
. The error message, if any, should be useful.One hackish fix that I've used is to load
items_controller.rb
before Rails start to autoload the controllers. You can either prepend theconfig.autoload_paths
array with the path, or you can add a manualrequire
to somewhere in yourapplication.rb
.
精彩评论