You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整ActiveAdmin登录后的重定向至admin/dashboard?

Fixing ActiveAdmin Login Redirect to Root Instead of Dashboard

Hey there, let's work through this ActiveAdmin redirect issue—this is a common gotcha, so I’ve got a few targeted fixes to try:

1. Check Devise’s After-Login Redirect Logic

The most likely culprit is a custom after_sign_in_path_for method in your application controller that’s overriding ActiveAdmin’s default behavior. If you’ve added this method for regular users, you need to make it distinguish between admin users and regular users.

Open app/controllers/application_controller.rb and update the method (or add it if it’s missing):

def after_sign_in_path_for(resource)
  # Redirect admin users to the dashboard, regular users to root
  if resource.is_a?(AdminUser)
    admin_dashboard_path
  else
    root_path
  end
end

This ensures admins get sent to the correct admin dashboard after login, while regular users still hit the root path as expected.

2. Verify ActiveAdmin’s Root Configuration

Double-check that your ActiveAdmin initializer isn’t misconfigured. Open config/initializers/active_admin.rb and confirm this line exists (it’s the default, but sometimes gets modified):

config.root_to = 'dashboard#index'

This tells ActiveAdmin where to send authenticated admins by default.

3. Fix Your Load Paths Modification

Your change to config.load_paths might be causing ActiveAdmin to miss critical files. Instead of replacing the default load paths, append your custom directory (if you need it):

# config/application.rb
config.load_paths += [File.join(Rails.root, "admin", "dashboard")]

Overwriting the entire load path with just the dashboard directory can prevent ActiveAdmin from loading other admin resources or core config. Also, make sure your dashboard file exists at app/admin/dashboard.rb (the default location) with the correct structure:

# app/admin/dashboard.rb
ActiveAdmin.register_page "Dashboard" do
  menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }

  content title: proc{ I18n.t("active_admin.dashboard") } do
    # Your dashboard content here
  end
end

4. Validate Your Routes

Ensure your config/routes.rb has the ActiveAdmin routes declared correctly, and no conflicting Devise routes are overriding them:

# Make sure this line is present (usually at the top of routes.rb)
ActiveAdmin.routes(self)

# Devise for admin users should look like this (no custom redirects unless intentional)
devise_for :admin_users, ActiveAdmin::Devise.config

5. Clear Cache & Restart

Rails cache can sometimes hold onto old route or config data. Run this command to clear temporary files, then restart your server:

rails tmp:clear

Try these steps in order—start with the after_sign_in_path_for fix, since that’s the most frequent cause of this exact issue. Let me know if any of these get you back to the admin dashboard!

内容的提问来源于stack exchange,提问作者Jason Harder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:10:46