管理 - Rails 4 | `add_route':无效的路线名称,已在使用中:' admin_root'

时间:2016-10-24 15:21:36

标签: ruby-on-rails ruby-on-rails-4 heroku routes

=>在Heroku上部署我的rails应用程序后

=>我无法访问mysite.heroku.com/admin上的管理员

-

我运行heroku日志

错误:已使用的路线名称无效:' admin_root'

/app/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/routing/route_set.rb:549:in `add_route': Invalid route name, already in use: 'admin_root'  (ArgumentError)

您可能使用:as选项

定义了两个具有相同名称的路线
 2016-10-24T13:43:56.930010+00:00 app[web.1]: You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: 

-

这是我的config / routes.rb:

Rails.application.routes.draw do
  root 'pages#index'
  get '/agence' => 'pages#agence'
  get '/methode' => 'pages#methode'
  get 'projets' => 'projet#index'
  get 'projets/:slug' => 'projet#show', as: 'projet'
  get '/article' => 'article#index'
  get '/article/:slug' => 'article#show', as: 'articles'
  get '/contact' => 'pages#contact'
  get '/mentionslegales' => 'pages#mentionslegales'


  namespace :admin do
    resources :projets
    resources :articles
    resources :users
    # get '/'  => 'projets#index'
    root to: "projets#index"

  end

  if defined?(DashboardManifest)
  namespace :admin do
    DashboardManifest::DASHBOARDS.each do |dashboard_resource|
      resources dashboard_resource
    end

    root controller: DashboardManifest::ROOT_DASHBOARD, action: :index
  end
end

-

耙路线:

                Prefix Verb   URI Pattern                        Controller#Action
              root GET    /                                  pages#index
            agence GET    /agence(.:format)                  pages#agence
           methode GET    /methode(.:format)                 pages#methode
           projets GET    /projets(.:format)                 projet#index
            projet GET    /projets/:slug(.:format)           projet#show
           article GET    /article(.:format)                 article#index
          articles GET    /article/:slug(.:format)           article#show
           contact GET    /contact(.:format)                 pages#contact
   mentionslegales GET    /mentionslegales(.:format)         pages#mentionslegales
     admin_projets GET    /admin/projets(.:format)           admin/projets#index
                   POST   /admin/projets(.:format)           admin/projets#create
  new_admin_projet GET    /admin/projets/new(.:format)       admin/projets#new
 edit_admin_projet GET    /admin/projets/:id/edit(.:format)  admin/projets#edit
      admin_projet GET    /admin/projets/:id(.:format)       admin/projets#show
                   PATCH  /admin/projets/:id(.:format)       admin/projets#update
                   PUT    /admin/projets/:id(.:format)       admin/projets#update
                   DELETE /admin/projets/:id(.:format)       admin/projets#destroy
    admin_articles GET    /admin/articles(.:format)          admin/articles#index
                   POST   /admin/articles(.:format)          admin/articles#create
 new_admin_article GET    /admin/articles/new(.:format)      admin/articles#new
edit_admin_article GET    /admin/articles/:id/edit(.:format) admin/articles#edit
     admin_article GET    /admin/articles/:id(.:format)      admin/articles#show
                   PATCH  /admin/articles/:id(.:format)      admin/articles#update
                   PUT    /admin/articles/:id(.:format)      admin/articles#update
                   DELETE /admin/articles/:id(.:format)      admin/articles#destroy
       admin_users GET    /admin/users(.:format)             admin/users#index
                   POST   /admin/users(.:format)             admin/users#create
    new_admin_user GET    /admin/users/new(.:format)         admin/users#new
   edit_admin_user GET    /admin/users/:id/edit(.:format)    admin/users#edit
        admin_user GET    /admin/users/:id(.:format)         admin/users#show
                   PATCH  /admin/users/:id(.:format)         admin/users#update
                   PUT    /admin/users/:id(.:format)         admin/users#update
                   DELETE /admin/users/:id(.:format)         admin/users#destroy
        admin_root GET    /admin(.:format)                   admin/projets#index

我不明白这个错误以及如何解决它。 我已经阅读了有关此错误的所有帖子,但无法找到解决方案..

1 个答案:

答案 0 :(得分:0)

最后解决方案是使用routes.rb绘制这些行:

     if defined?(DashboardManifest)
  namespace :admin do
    DashboardManifest::DASHBOARDS.each do |dashboard_resource|
      resources dashboard_resource
    end

    root controller: DashboardManifest::ROOT_DASHBOARD, action: :index
  end
end