Installing Active Admin and getting an ArgumentErr

2019-07-23 21:31发布

问题:

I'm trying to use ActiveAdmin for my first time w/ Rails 4. Upon installing all dependent gems, I try to run the installer, i.e.:

rails generate active_admin:install

Doing so gives me the following error:

in `add_route': Invalid route name, already in use: 'admin_root'  (ArgumentError)

However, I don't have any 'admin_root' route in routes.rb so I'm a little confused. Here's the output from running 'rake routes':

                  Prefix Verb   URI Pattern                                                        Controller#Action
               exams GET    /exams(.:format)                                                   exams#index
                     POST   /exams(.:format)                                                   exams#create
            new_exam GET    /exams/new(.:format)                                               exams#new
           edit_exam GET    /exams/:id/edit(.:format)                                          exams#edit
                exam GET    /exams/:id(.:format)                                               exams#show
                     PATCH  /exams/:id(.:format)                                               exams#update
                     PUT    /exams/:id(.:format)                                               exams#update
                     DELETE /exams/:id(.:format)                                               exams#destroy
    new_user_session GET    /users/sign_in(.:format)                                           devise/sessions#new
        user_session POST   /users/sign_in(.:format)                                           devise/sessions#create
destroy_user_session GET    /users/sign_out(.:format)                                          devise/sessions#destroy
       user_password POST   /users/password(.:format)                                          devise/passwords#create
   new_user_password GET    /users/password/new(.:format)                                      devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format)                                     devise/passwords#edit
                     PATCH  /users/password(.:format)                                          devise/passwords#update
                     PUT    /users/password(.:format)                                          devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                                            devise/registrations#cancel
       user_registration POST   /users(.:format)                                                   devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                                           devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                                              devise/registrations#edit
                         PATCH  /users(.:format)                                                   devise/registrations#update
                         PUT    /users(.:format)                                                   devise/registrations#update
                         DELETE /users(.:format)                                                   devise/registrations#destroy
                    root GET    /                                                                  composer#index
                    home GET    /home(.:format)                                                    home#index
                         GET    /exam_db/:exam_name/:chapter_name/:topic_name/:item_name(.:format) exam_db#gateway
         exam_db_gateway GET    /exam_db/gateway(.:format)                                         exam_db#gateway

Here's the full error:

gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:409:in `add_route': Invalid route name, already in use: 'admin_root'  (ArgumentError)
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:

Also worth noting, if I decide to skip the Devise user class altogether, it works:

rails generate active_admin:install --skip-users 

The only problem is, I'm not sure how to configure 'config/initializers/active_admin.rb' if I skip the Devise user class?

Any thoughts as to why this might be happening?

回答1:

I had the same error when upgrading to rails 4 with ActiveAdmin and it turned out this line was repeated twice in my routes.rb: ActiveAdmin.routes(self) I removed the second instance and the error went away.



回答2:

In addition to Andre's answer - as a result of the error the assets weren't installed properly. You'll have to run rails g active_admin:assets to get the js/css assets installed in the pipeline.