I created a rails (6.0.3) app and I added the thoughtbot/administrate and devise.
I have a User
model for normal users and another AdminUser
. I want to keep separated both types of users. Both were created with the devise generator
$ rails generate devise User
$ rails generate devise AdminUser
I'm having trouble with the route configuration of administrate and devise scope.
Rails.application.routes.draw do
devise_for :users
devise_scope :user do
get 'log-in', to: 'devise/sessions#new'
get 'sign-up', to: 'devise/registrations#new'
delete 'log-out', to: 'devise/sessions#destroy'
get 'reset-password', to: 'devise/passwords#new'
end
root 'pages#index'
get '/dashboard', to: 'pages#dashboard'
namespace :admin do
devise_for :admin_users
resources :users
resources :groups
root to: 'users#index'
end
end
I guess I'm missing something because it throwing an exception when I go to localhost:3000/admin
and it redirects to http://localhost:3000/admin/admin_users/sign_in
.
Here the exception:
Started GET "/admin" for ::1 at 2021-02-13 11:58:13 -0300
Processing by Admin::UsersController#index as HTML
Completed 401 Unauthorized in 2ms (ActiveRecord: 0.0ms | Allocations: 207)
Started GET "/admin/admin_users/sign_in" for ::1 at 2021-02-13 11:58:13 -0300
ActionController::RoutingError - uninitialized constant Admin::SessionsController:
Started POST "/__better_errors/6ee21cb1da542538/variables" for ::1 at 2021-02-13 11:58:13 -0300
the administrate application controller looks like this:
module Admin
class ApplicationController < Administrate::ApplicationController
before_action :authenticate_admin_user!
protected
def authenticate_admin_user!
authenticate_admin_admin_user!
end
end
end
LMK if there is something useful that I missed. Thanks in advance
The error is telling you that you have to define your controller.
admin/session_controller.rb
So create a controller which extended from devise session as you are using session different for normal user so you have to define admin users controller too.