0

我刚刚跑了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
4

3 回答 3

0

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

于 2014-09-29T18:33:32.027 回答
0

在您的路线文件中,您添加了ActiveAdmin.routes(self)两次尝试删除多余的文件并再次运行它

这可能是原因

于 2014-01-02T07:57:26.993 回答
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
于 2013-08-29T16:16:58.263 回答