使用 railsadmin 作为根应用程序

Use railsadmin as root app

我正在使用 rails_admin 作为主要应用程序,我希望通过 / 而不是 /admin 路径访问它。

我当前的路由文件如下所示:

Rails.application.routes.draw do
  mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
  devise_for :users
  root 'dashboard#index'
end

仪表板只是一个简单的页面,其中包含我想要删除的 link 到 /admin

一个简单的 mount RailsAdmin::Engine => '/', as: 'rails_admin' 无法解决,因为有一个重定向循环(我猜是来自设计)。

日志是

Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 10.0.16.183:3000, CTRL+C to stop


Started GET "/" for 10.0.16.244 at 2016-01-15 14:19:55 +0100
Cannot render console from 10.0.16.244! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  ActiveRecord::SchemaMigration Load (0.3ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by RailsAdmin::MainController#dashboard as HTML
Completed 401 Unauthorized in 12ms (ActiveRecord: 0.0ms)


Started GET "/users/sign_in" for 10.0.16.244 at 2016-01-15 14:19:55 +0100
Cannot render console from 10.0.16.244! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by RailsAdmin::MainController#show as HTML
  Parameters: {"model_name"=>"users", "id"=>"sign_in"}
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)


Started GET "/users/sign_in" for 10.0.16.244 at 2016-01-15 14:19:55 +0100
Cannot render console from 10.0.16.244! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by RailsAdmin::MainController#show as HTML
Parameters: {"model_name"=>"users", "id"=>"sign_in"}
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)


...
continues a couple of time after timeout

尝试了几件事,但没有成功。

有人可以帮忙吗?

您尝试过指定根地址吗?

mount RailsAdmin::Engine => '/', as: 'rails_admin'

是一个设计问题,我在 https://github.com/sferik/rails_admin/wiki/Troubleshoot 中找到了解决方案 必须在发动机安装前切换设计。

Rails.application.routes.draw do
  devise_for :users
  mount RailsAdmin::Engine => '/', as: 'rails_admin'
  root 'dashboard#index'
end

对我来说,下面的工作是将具有管理员角色的用户直接重定向到 rails_admin 仪表板页面。

  devise_for :users, controllers: { registrations: 'registrations' }
  mount RailsAdmin::Engine => '/admin', as: 'rails_admin'

  authenticated :user, ->(u) { u.has_role?(:admin) } do
    root to: "rails_admin/main#dashboard", as: :admin_root
  end