将root重定向到/ admin

时间:2015-03-10 19:20:35

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 routes activeadmin

我有一个非常奇怪的问题,在一瞬间我得到了这个工作,但现在总是失败。

我希望/ admin后缀成为我的应用的根页面。

我试过了:

root to: redirect('/admin')
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

这:

  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  get '/', to: redirect('/admin')

这个(没有运气):

  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  root to: 'admin/dashboard#index'

我认为最后一个选项是昨天工作的片段,但我不确定。

编辑** RAKE ROUTES ADDED **

Prefix Verb       URI Pattern                               Controller#Action
                          root GET        /                                         admin/dashboard#index
                    admin_root GET        /admin(.:format)                          admin/dashboard#index
batch_action_admin_admin_users POST       /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
             admin_admin_users GET        /admin/admin_users(.:format)              admin/admin_users#index
                               POST       /admin/admin_users(.:format)              admin/admin_users#create
          new_admin_admin_user GET        /admin/admin_users/new(.:format)          admin/admin_users#new
         edit_admin_admin_user GET        /admin/admin_users/:id/edit(.:format)     admin/admin_users#edit
              admin_admin_user GET        /admin/admin_users/:id(.:format)          admin/admin_users#show
                               PATCH      /admin/admin_users/:id(.:format)          admin/admin_users#update
                               PUT        /admin/admin_users/:id(.:format)          admin/admin_users#update
                               DELETE     /admin/admin_users/:id(.:format)          admin/admin_users#destroy
      batch_action_admin_cases POST       /admin/cases/batch_action(.:format)       admin/cases#batch_action
                   admin_cases GET        /admin/cases(.:format)                    admin/cases#index
                               POST       /admin/cases(.:format)                    admin/cases#create
                new_admin_case GET        /admin/cases/new(.:format)                admin/cases#new
               edit_admin_case GET        /admin/cases/:id/edit(.:format)           admin/cases#edit
                    admin_case GET        /admin/cases/:id(.:format)                admin/cases#show
                               PATCH      /admin/cases/:id(.:format)                admin/cases#update
                               PUT        /admin/cases/:id(.:format)                admin/cases#update
                               DELETE     /admin/cases/:id(.:format)                admin/cases#destroy
               admin_dashboard GET        /admin/dashboard(.:format)                admin/dashboard#index
       batch_action_admin_tags POST       /admin/tags/batch_action(.:format)        admin/tags#batch_action
                    admin_tags GET        /admin/tags(.:format)                     admin/tags#index
                               POST       /admin/tags(.:format)                     admin/tags#create
                 new_admin_tag GET        /admin/tags/new(.:format)                 admin/tags#new
                edit_admin_tag GET        /admin/tags/:id/edit(.:format)            admin/tags#edit
                     admin_tag GET        /admin/tags/:id(.:format)                 admin/tags#show
                               PATCH      /admin/tags/:id(.:format)                 admin/tags#update
                               PUT        /admin/tags/:id(.:format)                 admin/tags#update
                               DELETE     /admin/tags/:id(.:format)                 admin/tags#destroy
                admin_comments GET        /admin/comments(.:format)                 admin/comments#index
                               POST       /admin/comments(.:format)                 admin/comments#create
                 admin_comment GET        /admin/comments/:id(.:format)             admin/comments#show
        new_admin_user_session GET        /admin/login(.:format)                    active_admin/devise/sessions#new
            admin_user_session POST       /admin/login(.:format)                    active_admin/devise/sessions#create
    destroy_admin_user_session DELETE|GET /admin/logout(.:format)                   active_admin/devise/sessions#destroy
           admin_user_password POST       /admin/password(.:format)                 active_admin/devise/passwords#create
       new_admin_user_password GET        /admin/password/new(.:format)             active_admin/devise/passwords#new
      edit_admin_user_password GET        /admin/password/edit(.:format)            active_admin/devise/passwords#edit
                               PATCH      /admin/password(.:format)                 active_admin/devise/passwords#update
                               PUT        /admin/password(.:format)                 active_admin/devise/passwords#update 

你建议做什么?有什么想法吗?

1 个答案:

答案 0 :(得分:6)

你几乎做对了!

您将根路径设置为:root to: redirect('/admin')

有了这个,你还必须明确地声明它被路由到的路由,如下所示:match '/admin', to: 'admin/dashboard#index', via: :get

这样,每次调用后,你的根路径都会自动调用后一个路径和控制器。

为了澄清一下,您的设置将如下所示:

TestActiveAdmin::Application.routes.draw do 
  root to: redirect('/admin')
  match '/admin', to: 'admin/dashboard#index', via: :get

  ActiveAdmin.routes(self)

  devise_for :admin_users, ActiveAdmin::Devise.config

  ...
end

然后您可以在Rails控制台中验证:rake routes | grep root

你应该看到类似的东西: root /admin {:controller => 'admin/dashboard, :action => 'index'