我创建了一个 rails (6.0.3) 应用程序,并添加了thinkbot/administrate和devise。我有一个User
普通用户的模型和另一个AdminUser
. 我想将两种类型的用户分开。两者都是用设计生成器创建的
$ rails generate devise User
$ rails generate devise AdminUser
我在管理和设计范围的路由配置方面遇到问题。
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
我想我错过了一些东西,因为当我转到localhost:3000/admin
它时它会抛出异常并重定向到http://localhost:3000/admin/admin_users/sign_in
. 这里有一个例外:
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
管理应用程序控制器如下所示:
module Admin
class ApplicationController < Administrate::ApplicationController
before_action :authenticate_admin_user!
protected
def authenticate_admin_user!
authenticate_admin_admin_user!
end
end
end
LMK 如果我错过了一些有用的东西。提前致谢