Invalid route name, already in use: 'admin_roo

2020-05-03 03:09发布

问题:

I ran:

rails g active_admin:install

and got this error:

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: 

I can't even run rake routes. I get the same error when I do so.

Here is my routes file:

Stynyl::Application.routes.draw do 
  resources :things

  devise_for :users

  resources :users, only: [:show, :new, :create]


  get '/about', to: 'pages#about'
  root 'things#index'

end

EDITS

I did a:

rails destroy active_admin:install

and ran the install command again. Getting the same error. Invalid route name, already in use.

Cleared ActiveAdmin from schema. Still getting error.

Also noticed that the uninstall wasn't 100% clean. Left behind some styling and javascript files, but those don't seem to be affecting the application at all.

I updated my Gemfile like this:

gem 'activeadmin',         github: 'gregbell/active_admin'
gem 'ransack',             github: 'ernie/ransack'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'formtastic',          github: 'justinfrench/formtastic'

group :development do
  gem 'sqlite3'
end

Tried to run the ActiveAdmin install generator and got the same error. I cannot migrate the database. Here is the error I get:

SQLite3::SQLException: table "admin_users" already exists: CREATE TABLE "admin_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255) DEFAULT '' NOT NULL, "encrypted_password" varchar(255) DEFAULT '' NOT NULL, "reset_password_token" varchar(255), "reset_password_sent_at" datetime, "remember_created_at" datetime, "sign_in_count" integer DEFAULT 0 NOT NULL, "current_sign_in_at" datetime, "last_sign_in_at" datetime, "current_sign_in_ip" varchar(255), "last_sign_in_ip" varchar(255), "created_at" datetime, "updated_at" datetime) /Users/DylanRichards/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'

Checked my schema file and I don't even see the table "admin_users".

What I can do now, however, is run rake routes. Here is the output:

Prefix Verb       URI Pattern                               Controller#Action
        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
                        things GET        /things(.:format)                         things#index
                               POST       /things(.:format)                         things#create
                 new_thing     GET        /things/new(.:format)                     things#new
                edit_thing     GET        /things/:id/edit(.:format)                things#edit
                     thing     GET        /things/:id(.:format)                     things#show
                               PATCH      /things/:id(.:format)                     things#update 
                               PUT        /things/:id(.:format)                     things#update
                               DELETE     /things/:id(.:format)                     things#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     DELETE     /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
                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
           admin_dashboard     GET        /admin/dashboard(.:format)                admin/dashboard#index
   batch_action_admin_comments     POST       /admin/comments/batch_action(.:format)    admin/comments#batch_action
            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
                     users     POST       /users(.:format)                          users#create
                  new_user     GET        /users/new(.:format)                      users#new
                      user     GET        /users/:id(.:format)                      users#show
                     about     GET        /about(.:format)                          pages#about
                      root     GET        /                                         things#index

回答1:

So I found someone having the same problem in this issue-- but that says the problem is that ActiveAdmin puts ActiveAdmin.routes(self) in your config/routes.rb file twice.

However, your routes doesn't have that line at all-- which I'm guessing is because you ran rails destroy active_admin:install, but that doesn't explain why you're STILL getting that error after destroying.

Are you using git? Can you see if there were any other modifications made by the generate that might not have been cleaned up by the destroy? The ActiveAdmin issue also hints that if an error happens during generation, the generation doesn't finish correctly.

Another thing to try would be run the generator again, then check your routes and make sure ActiveAdmin.routes(self) only appears once.



回答2:

Solved it by uninstalling ActiveAdmin, reinstalling it, deleting the second ActiveAdmin.routes(self) in my routes file, then deleting my schema file. After that, I ran rake db:reset and remigrated the database.