Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - superclass mismatch

Playing with Rails and controller inheritance.

I've created a controller called AdminController, with a child class called admin_user_controller placed in /app/controllers/admin/admin_user_controller.rb

This is my routes.rb

  namespace :admin do
    resources :admin_user # Have the admin manage them here.
  end

app/controllers/admin/admin_user_controller.rb

class AdminUserController < AdminController
  def index
    @users = User.all
  end
end

app/controllers/admin_controller.rb

class AdminController < ApplicationController

end

I have a user model which I will want to edit with admin privileges.

When I try to connect to: http://localhost:3000/admin/admin_user/

I receive this error:

superclass mismatch for class AdminUserController
like image 298
Philip Avatar asked Mar 11 '13 18:03

Philip


2 Answers

This error shows up if you define two times the same class with different superclasses. Maybe try grepping class AdminUserController in your code so you're sure you're not defining it two times. Chances are there is a conflict with a file generated by Rails.

like image 163
Intrepidd Avatar answered Oct 19 '22 23:10

Intrepidd


To complete what @Intrepidd said, you can wrap your class inside a module, so that the AdminUserController class doesn't inherit twice from ApplicationController, so a simple workaround would be :

module Admin
  class AdminUserController < AdminController
    def index
      @users = User.all
    end
  end
end
like image 24
epsilones Avatar answered Oct 20 '22 00:10

epsilones