qpingu
qpingu

Reputation: 960

Rails 3 Admin Namespace Issue

I'm migrating the majority of my application to the admin namespace and while there are lots of guides related to this, I still can't manage. I've been primarily following this answer, along with any results Google brings up (they all tend to agree). Could somebody please tell me what I'm doing wrong so I don't lose any more sleep?

Here is the error message:

wrong argument type Module (expected Class)

app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/admin/admin_controller.rb:1:in `<top (required)>'
app/controllers/admin/home_controller.rb:1:in `<top (required)>'

routes.rb

namespace :admin do 
  root :to => "home#index"

  resources :users
end

admin/admin_controller.rb

class Admin::AdminController < ApplicationController

admin/home_controller.rb

class Admin::HomeController < Admin::AdminController

admin/users_controller.rb

class Admin::UsersController < Admin::AdminController

I'm mostly sure it's something simple to related to the module and controller interaction, so I haven't included any other code. However, I should have found the solution by now and please let me know if any additional code is required.

Thanks.

Upvotes: 9

Views: 5953

Answers (7)

mspanc
mspanc

Reputation: 550

I encountered such problem when I used paperclip's has_attached_file with invalid parameters.

Upvotes: 0

Johann
Johann

Reputation: 391

@Russell, I got that problem having created model AdminHelper (meant to contain admin help messages) :)

be careful in naming things!

Upvotes: 0

Russell
Russell

Reputation: 390

I encountered the reverse problem "wrong argument type Class (expected Module)" and it turned out there was a helper defined as a Class instead of a Module, so try searching for classes that are inadvertently defined as modules. Like a controller defined as a Module.

Upvotes: 6

Amal Kumar S
Amal Kumar S

Reputation: 16075

Can u follow the below code, Your controllers are fine, can you use the routes I have specified here.

 class Admin::AdminController < ApplicationController


 class Admin::UsersController < Admin::AdminController

This is same as what you have written, I think so.

namespace :admin do
   resources :users do as_routes end
end
root :to => "home#index"

Upvotes: 0

Jonas Bylov
Jonas Bylov

Reputation: 1524

I'd suggest you rename Admin::AdminController to Admin::BaseController.

Upvotes: 3

adzdavies
adzdavies

Reputation: 1555

"wrong argument type Module (expected Class)"

This means you are defining a 'class' but that name is already defined as a 'module' somewhere else. Search for what that could be...

Upvotes: 0

Mirko
Mirko

Reputation: 5286

Maybe you have something defined as Admin constant?
Try a fresh app with the same structure then add pieces from the current one and see where it breaks (Not so great suggestion, huh?).

I use the same organization for admin as you pasted...

Upvotes: 0

Related Questions