使用railsadmin作为root应用程序

时间:2016-01-15 11:49:05

标签: ruby-on-rails devise routes rails-admin

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

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

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

信息中心只是一个简单的页面,其中包含我想要摆脱的/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

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

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:1)

您是否尝试过指定根地址?

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

答案 1 :(得分:1)

是一个设计问题,我在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

答案 2 :(得分:0)

对我来说,以下工作将具有管理员角色的用户直接重定向到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