Rails - superclass mismatch

Playing with Rails and controller inheritance.

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

These are my .rb routes

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

application / controllers / admin / admin_user_controller.rb

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

application / controllers / admin_controller.rb

class AdminController < ApplicationController

end

I have a custom model that I want to edit with administrator privileges.

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

I get this error:

superclass mismatch for class AdminUserController
+5
source share
3 answers

To complete what @Intrepidd said, you can wrap your class inside a module so that the class AdminUserControllerdoes not inherit twice from ApplicationController, so a simple workaround would be the following:

module Admin
  class AdminUserController < AdminController
    def index
      @users = User.all
    end
  end
end
+6

, . , grepping class AdminUserController , , . , , Rails.

+8

I fixed it by creating a "Dashboard" and "index" def controller. Then I edited my .rb routes:

Rails.application.routes.draw do



namespace :admin do
    get '', to: 'dashboard#index', as: '/'

    resources :posts
end



end
0
source

All Articles