安装activeadmin搞乱了我的路由不兼容问题

时间:2013-08-29 15:26:29

标签: ruby-on-rails activeadmin

我刚刚运行rails g active_admin:install,标准是它生成并在我的rails应用程序上安装了一堆文件。当我跑步时,我得到了这个

/Users/judyngai/.rvm/gems/ruby-2.0.0-p195/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: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

现在这是我的路线的样子

Lintong::Application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  #get 'signup', to: 'students#signup'


  root :to => 'students#signup'

  resources :students #may not be necessary 

  devise_for :students
  ActiveAdmin.routes(self)
  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end

  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable

  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
end

我做不到rails s

我得到了这个,同样的错误。我对路线不是很熟悉,并会阅读它。我希望有人可以向我解释我做错了什么以及如何解决这个问题。

/Users/judyngai/.rvm/gems/ruby-2.0.0-p195/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: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

3 个答案:

答案 0 :(得分:0)

听起来像是你大部分时间 - 只需仔细检查你的步数和输出

从一开始你就可以看到你在这个过程中的位置。

添加到您的gemfile

  gem 'activeadmin'

安装

 bundle install

运行安装生成器

rails generate active_admin:install

运行它应该吐出数据,告诉你在你的应用程序中创建了哪些文件。它看起来像:

      invoke  devise
generate    No need to install devise, already done.
  invoke    active_record
  create      db/migrate/20130829160843_devise_create_admin_users.rb
  create      app/models/admin_user.rb
  invoke      rspec
  create        spec/models/admin_user_spec.rb
  invoke        factory_girl
  create          spec/factories/admin_users.rb
  insert      app/models/admin_user.rb
   route    devise_for :admin_users
    gsub    app/models/admin_user.rb
    gsub    config/routes.rb
  insert    db/migrate/20130829160843_devise_create_admin_users.rb
  create  config/initializers/active_admin.rb
  create  app/admin
  create  app/admin/dashboard.rb
  create  app/admin/admin_user.rb
  insert  config/routes.rb
generate  active_admin:assets
  create  app/assets/javascripts/active_admin.js
  create  app/assets/stylesheets/active_admin.css.scss
  create  db/migrate/20130829160852_create_admin_notes.rb
  create  db/migrate/20130829160853_move_admin_notes_to_comments.rb

只要您看到该字符串,您就拥有了入门所需的文件。此时,您的路由中只有一个条目用于ActiveAdmin

现在迁移

bundle exec rake db:migrate

重新启动服务器,您应该能够登录。

现在设置模型

rails generate active_admin:resource ModelNameHere

答案 1 :(得分:0)

在您的路线文件中,您已添加ActiveAdmin.routes(self)两次 尝试删除额外的一个并再次运行

可能是

的原因

答案 2 :(得分:0)

我有同样的问题。通过在迁移活动管理员更改后重新启动我的服务器来修复它。