如何修复activeadmin中的重复路由?

时间:2015-09-28 19:29:54

标签: ruby-on-rails ruby-on-rails-4 activeadmin

请帮助解决问题。

我使用gem' activeadmin'版本1.0.0。我的路线文件是:

Rails.application.routes.draw do
  ActiveAdmin.routes(self)
  devise_for :users, ActiveAdmin::Devise.config
  resources :reviews
  root 'reviews#index'
end

rake routes:

kalinin@kalinin ~/rails/admin_book $ rake routes
                    Prefix Verb       URI Pattern                           Controller#Action
                admin_root GET        /admin(.:format)                      admin/dashboard#index
batch_action_admin_reviews POST       /admin/reviews/batch_action(.:format) admin/reviews#batch_action
             admin_reviews GET        /admin/reviews(.:format)              admin/reviews#index
                           POST       /admin/reviews(.:format)              admin/reviews#create
          new_admin_review GET        /admin/reviews/new(.:format)          admin/reviews#new
         edit_admin_review GET        /admin/reviews/:id/edit(.:format)     admin/reviews#edit
              admin_review GET        /admin/reviews/:id(.:format)          admin/reviews#show
                           PATCH      /admin/reviews/:id(.:format)          admin/reviews#update
                           PUT        /admin/reviews/:id(.:format)          admin/reviews#update
                           DELETE     /admin/reviews/:id(.:format)          admin/reviews#destroy
           admin_dashboard GET        /admin/dashboard(.:format)            admin/dashboard#index
  batch_action_admin_users POST       /admin/users/batch_action(.:format)   admin/users#batch_action
               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_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
                           DELETE     /admin/comments/:id(.:format)         admin/comments#destroy
          new_user_session GET        /admin/login(.:format)                active_admin/devise/sessions#new
              user_session POST       /admin/login(.:format)                active_admin/devise/sessions#create
      destroy_user_session DELETE|GET /admin/logout(.:format)               active_admin/devise/sessions#destroy
             user_password POST       /admin/password(.:format)             active_admin/devise/passwords#create
         new_user_password GET        /admin/password/new(.:format)         active_admin/devise/passwords#new
        edit_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
                   reviews GET        /reviews(.:format)                    reviews#index
                           POST       /reviews(.:format)                    reviews#create
                new_review GET        /reviews/new(.:format)                reviews#new
               edit_review GET        /reviews/:id/edit(.:format)           reviews#edit
                    review GET        /reviews/:id(.:format)                reviews#show
                           PATCH      /reviews/:id(.:format)                reviews#update
                           PUT        /reviews/:id(.:format)                reviews#update
                           DELETE     /reviews/:id(.:format)                reviews#destroy
                      root GET        /                                     reviews#index

通过&#;; rails server'运行我的应用程序后并打开地址http://localhost:3000/admin,浏览器显示以下错误消息:

  

Admin :: DashboardController中的NameError #index uninitialized constant   仪表板

请帮忙解决。

PS: 我读了这个帖子: https://github.com/activeadmin/activeadmin/issues/2053 但它没有帮助

PS2: 我不想使用0.6.0版本

回溯:

Started GET "/admin" for 127.0.0.1 at 2015-09-28 23:32:20 +0300
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by Admin::DashboardController#index as HTML
Completed 500 Internal Server Error in 20ms (ActiveRecord: 0.0ms)

NameError (uninitialized constant Dashboard):
  activesupport (4.2.1) lib/active_support/inflector/methods.rb:261:in `const_get'
  activesupport (4.2.1) lib/active_support/inflector/methods.rb:261:in `block in constantize'
  activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:in `each'
  activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:in `inject'
  activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:in `constantize'
  activesupport (4.2.1) lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
  cancancan (1.12.0) lib/cancan/controller_resource.rb:150:in `resource_class'
  cancancan (1.12.0) lib/cancan/controller_resource.rb:157:in `resource_class_with_parent'
  cancancan (1.12.0) lib/cancan/controller_resource.rb:41:in `authorize_resource'
  cancancan (1.12.0) lib/cancan/controller_resource.rb:26:in `load_and_authorize_resource'
  cancancan (1.12.0) lib/cancan/controller_resource.rb:10:in `block in add_before_filter'
  activesupport (4.2.1) lib/active_support/callbacks.rb:448:in `instance_exec'
  activesupport (4.2.1) lib/active_support/callbacks.rb:448:in `block in make_lambda'
  activesupport (4.2.1) lib/active_support/callbacks.rb:164:in `call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:164:in `block in halting'
  activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `block in call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `each'
  activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.1) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.1) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.1) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.1) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `call'
  actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
  actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in `serve'
  actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `catch'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.6.4) lib/rack/etag.rb:24:in `call'
  rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.4) lib/rack/head.rb:13:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.1) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
  activerecord (4.2.1) lib/active_record/migration.rb:378:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `call'
  activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
  activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.1) lib/rails/engine.rb:518:in `call'
  railties (4.2.1) lib/rails/application.rb:164:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /home/kalinin/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /home/kalinin/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /home/kalinin/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

应用程序/管理/ dashboard.rb:

ActiveAdmin.register_page "Dashboard" do

  menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }

  content title: proc{ I18n.t("active_admin.dashboard") } do
    div class: "blank_slate_container", id: "dashboard_default_message" do
      span class: "blank_slate" do
        span I18n.t("active_admin.dashboard_welcome.welcome")
        small I18n.t("active_admin.dashboard_welcome.call_to_action")
      end
    end 

    columns do
      column do
        panel "Other links" do
          link_to("to public", root_path)
        end
      end

      column do
        panel "other info" do
          'lorem ipsum '
        end
      end      
    end
end
end

并链接到git:https://github.com/zlodiak/admin_book

1 个答案:

答案 0 :(得分:0)

问题似乎不在您的路线中。再看一下错误:

  

Admin :: DashboardController中的NameError #index uninitialized constant   仪表板

看来您有一个名为DashboardController的控制器,其中有代码处理'索引',即HTTP GET动词。该代码失败,因为您有一个未使用值初始化的名为Dashboard的常量。