In the output of rake routes
you can see that for these route routes with names, use :controller => 'admin/admin'
. When it comes to defining a controller class, it converts admin/admin
to Admin::AdminController
. Therefore, controllers for routes with names are usually placed in the app/controllers/namespace_name
directory and wrapped in the NamespaceName
module. In your case, it should be the class Admin::AdminController
defined in app/controllers/admin/admin_controller.rb
.
Although itβs really interesting why your configuration works fine in development, it breaks down in production mode (I tried and successfully reproduced it). I believe this is related to loading and caching classes in production mode, because setting config.cache_classes = true
in config/environments/development.rb
causes it to break in development mode too.
And as zoltarSpeaks noted, it should be root :to => "admin#index"
instead of root :to => "admin#index"
.
One more note: namespaces for routes are usually used when there are several connected controllers. If you need only one AdminController
, you can configure your routes as follows:
resources :admin, :only => :index
In this case, no other changes are required (if you want to have other default actions besides index
, just remove the :only
option).
source share