ruby-on-rails – Rails_Admin显示路由错误“无路由匹配{:contr
我按照说明安装了Rails_Admin,也使用了Devise.当我尝试导航到“/ admin”时,我收到以下错误:
Routing Error No route matches {:controller=>"home"} 这是我的routes.rb: Ot::Application.routes.draw do resources :badgeships resources :badges resources :profiles resources :universities resources :degrees resources :jobs resources :resources resources :communities resources :networks resources :topics do resources :posts end get 'topics/tag/:tag',to: 'topics#index',as: :topic_tag get 'resources/tag/:tag',to: 'resources#index',as: :resource_tag root :to => 'home#index' devise_for :users,path_names: {sign_in: "login",sign_out: "logout"} mount RailsAdmin::Engine => '/admin',:as => 'rails_admin' end 这是我的rails_admin.rb初始化程序: RailsAdmin.config do |config| config.main_app_name = ["Cool app","BackOffice"] # or somethig more dynamic config.main_app_name = Proc.new { |controller| [ "Cool app","BackOffice - #{controller.params[:action].try(:titleize)}" ] } end 有关如何让rails_admin正常工作的任何想法? 更新:这是我的佣金路线: [RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it. badgeships GET /badgeships(.:format) badgeships#index POST /badgeships(.:format) badgeships#create new_badgeship GET /badgeships/new(.:format) badgeships#new edit_badgeship GET /badgeships/:id/edit(.:format) badgeships#edit badgeship GET /badgeships/:id(.:format) badgeships#show PUT /badgeships/:id(.:format) badgeships#update DELETE /badgeships/:id(.:format) badgeships#destroy badges GET /badges(.:format) badges#index POST /badges(.:format) badges#create new_badge GET /badges/new(.:format) badges#new edit_badge GET /badges/:id/edit(.:format) badges#edit badge GET /badges/:id(.:format) badges#show PUT /badges/:id(.:format) badges#update DELETE /badges/:id(.:format) badges#destroy profiles GET /profiles(.:format) profiles#index POST /profiles(.:format) profiles#create new_profile GET /profiles/new(.:format) profiles#new edit_profile GET /profiles/:id/edit(.:format) profiles#edit profile GET /profiles/:id(.:format) profiles#show PUT /profiles/:id(.:format) profiles#update DELETE /profiles/:id(.:format) profiles#destroy universities GET /universities(.:format) universities#index POST /universities(.:format) universities#create new_university GET /universities/new(.:format) universities#new edit_university GET /universities/:id/edit(.:format) universities#edit university GET /universities/:id(.:format) universities#show PUT /universities/:id(.:format) universities#update DELETE /universities/:id(.:format) universities#destroy degrees GET /degrees(.:format) degrees#index POST /degrees(.:format) degrees#create new_degree GET /degrees/new(.:format) degrees#new edit_degree GET /degrees/:id/edit(.:format) degrees#edit degree GET /degrees/:id(.:format) degrees#show PUT /degrees/:id(.:format) degrees#update DELETE /degrees/:id(.:format) degrees#destroy jobs GET /jobs(.:format) jobs#index POST /jobs(.:format) jobs#create new_job GET /jobs/new(.:format) jobs#new edit_job GET /jobs/:id/edit(.:format) jobs#edit job GET /jobs/:id(.:format) jobs#show PUT /jobs/:id(.:format) jobs#update DELETE /jobs/:id(.:format) jobs#destroy resources GET /resources(.:format) resources#index POST /resources(.:format) resources#create new_resource GET /resources/new(.:format) resources#new edit_resource GET /resources/:id/edit(.:format) resources#edit resource GET /resources/:id(.:format) resources#show PUT /resources/:id(.:format) resources#update DELETE /resources/:id(.:format) resources#destroy communities GET /communities(.:format) communities#index POST /communities(.:format) communities#create new_community GET /communities/new(.:format) communities#new edit_community GET /communities/:id/edit(.:format) communities#edit community GET /communities/:id(.:format) communities#show PUT /communities/:id(.:format) communities#update DELETE /communities/:id(.:format) communities#destroy networks GET /networks(.:format) networks#index POST /networks(.:format) networks#create new_network GET /networks/new(.:format) networks#new edit_network GET /networks/:id/edit(.:format) networks#edit network GET /networks/:id(.:format) networks#show PUT /networks/:id(.:format) networks#update DELETE /networks/:id(.:format) networks#destroy topic_posts GET /topics/:topic_id/posts(.:format) posts#index POST /topics/:topic_id/posts(.:format) posts#create new_topic_post GET /topics/:topic_id/posts/new(.:format) posts#new edit_topic_post GET /topics/:topic_id/posts/:id/edit(.:format) posts#edit topic_post GET /topics/:topic_id/posts/:id(.:format) posts#show PUT /topics/:topic_id/posts/:id(.:format) posts#update DELETE /topics/:topic_id/posts/:id(.:format) posts#destroy topics GET /topics(.:format) topics#index POST /topics(.:format) topics#create new_topic GET /topics/new(.:format) topics#new edit_topic GET /topics/:id/edit(.:format) topics#edit topic GET /topics/:id(.:format) topics#show PUT /topics/:id(.:format) topics#update DELETE /topics/:id(.:format) topics#destroy topic_tag GET /topics/tag/:tag(.:format) topics#index resource_tag GET /resources/tag/:tag(.:format) resources#index root / home#index new_user_session GET /users/login(.:format) devise/sessions#new user_session POST /users/login(.:format) devise/sessions#create destroy_user_session DELETE /users/logout(.:format) devise/sessions#destroy user_omniauth_authorize /users/auth/:provider(.:format) devise/omniauth_callbacks#passthru {:provider=>/facebook/} user_omniauth_callback /users/auth/:action/callback(.:format) devise/omniauth_callbacks#(?-mix:facebook) 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 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 PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy rails_admin /admin RailsAdmin::Engine Routes for RailsAdmin::Engine: dashboard GET / rails_admin/main#dashboard index GET|POST /:model_name(.:format) rails_admin/main#index new GET|POST /:model_name/new(.:format) rails_admin/main#new export GET|POST /:model_name/export(.:format) rails_admin/main#export bulk_delete POST|DELETE /:model_name/bulk_delete(.:format) rails_admin/main#bulk_delete history_index GET /:model_name/history(.:format) rails_admin/main#history_index bulk_action POST /:model_name/bulk_action(.:format) rails_admin/main#bulk_action show GET /:model_name/:id(.:format) rails_admin/main#show edit GET|PUT /:model_name/:id/edit(.:format) rails_admin/main#edit delete GET|DELETE /:model_name/:id/delete(.:format) rails_admin/main#delete history_show GET /:model_name/:id/history(.:format) rails_admin/main#history_show show_in_app GET /:model_name/:id/show_in_app(.:format) rails_admin/main#show_in_app 以下是我安装rails_admin的方法: rails g rails_admin:install SECURITY WARNING: No secret option provided to Rack::Session::Cookie. This poses a security threat. It is strongly recommended that you provide a secret to prevent exploits that may be possible from crafted cookies. This will not be supported in future versions of Rack,and future versions will even invalidate your existing user cookies. Called from: /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.9/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'. - Hello,RailsAdmin installer will help you set things up! - I need to work with Devise,let's look at a few things first: - Checking for a current installation of devise... - Found it! - Looks like you've already installed it,good! ? Where do you want to mount rails_admin? Press <enter> for [admin] > manage gsub config/routes.rb route mount RailsAdmin::Engine => '/manage',:as => 'rails_admin' - And you already set it up,good! We just need to know about your user model name... - We found 'user' (should be one of 'user','admin',etc.) ? Correct Devise model name if needed. Press <enter> for [user] > User - Now setting up devise with user model name 'User': generate devise SECURITY WARNING: No secret option provided to Rack::Session::Cookie. This poses a security threat. It is strongly recommended that you provide a secret to prevent exploits that may be possible from crafted cookies. This will not be supported in future versions of Rack,and future versions will even invalidate your existing user cookies. Called from: /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.9/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'. invoke active_record create db/migrate/20130214195616_add_devise_to_users.rb insert app/models/user.rb route devise_for :users - Now you'll need an initializer... - You already have a config file. You're updating,heh? I'm generating a new 'rails_admin.rb.example' that you can review. create config/initializers/rails_admin.rb.example /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in `block in source_reflection': undefined method `klass' for nil:NilClass (NoMethodError) from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in `collect' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in `source_reflection' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:375:in `rescue in foreign_key' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:373:in `foreign_key' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:292:in `association_foreign_key_lookup' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:72:in `block in associations' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:65:in `map' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:65:in `associations' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields/factories/association.rb:6:in `block in <top (required)>' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `call' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `block (2 levels) in factory' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `each' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `find' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `block in factory' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:50:in `each' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:50:in `factory' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:130:in `_fields' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:128:in `_fields' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:108:in `all_fields' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:83:in `fields' from (erb):64:in `block in template' from (erb):53:in `map' from (erb):53:in `template' from /Users/iyerushalmi/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/erb.rb:838:in `eval' from /Users/iyerushalmi/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/erb.rb:838:in `result' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/file_manipulation.rb:117:in `block in template' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:54:in `call' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:54:in `render' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:63:in `block (2 levels) in invoke!' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:63:in `open' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:63:in `block in invoke!' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/empty_directory.rb:133:in `call' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/empty_directory.rb:133:in `invoke_with_conflict_check' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:61:in `invoke!' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions.rb:95:in `action' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:26:in `create_file' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/file_manipulation.rb:116:in `template' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/generators/rails_admin/install_generator.rb:66:in `install' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/task.rb:27:in `run' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:120:in `invoke_task' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `block in invoke_all' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `each' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `map' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `invoke_all' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/group.rb:238:in `dispatch' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/base.rb:434:in `start' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.9/lib/rails/generators.rb:171:in `invoke' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.9/lib/rails/commands/generate.rb:12:in `<top (required)>' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require' from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.9/lib/rails/commands.rb:29:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>' 解决方法
编辑:找到修复程序.见
this SO discussion.
进入主ApplicationController并进行更改 rescue_from CanCan::AccessDenied do |e| redirect_to root_path,alert: e.message end 至 rescue_from CanCan::AccessDenied do |e| redirect_to '/',alert: e.message end 给它任何符号路径名称将导致RoutingException,因为Rails正在错误的路由表中查找名称.指定文字根路径会绕过查找,并在处理它时为主应用程序的ApplicationController提供第一个破解.这是你想要的. 小时以下的原帖: 我遇到了类似的错误,如果非管理员用户访问我的’/ admin’路由,那么ActiveAdmin CanCan会尝试将他踢出去. (顺便说一下,通过添加better_errors Gem可以获得更清晰的错误报告.)我得到异常报告,我可以在发生路由故障时在本地变量中看到正确的错误消息. 我还可以看到,感谢better_errors的“live shell”,生成RoutingError的ActionController是RailsAdmin :: MainController.这告诉我,我们需要弄清楚如何告诉RailsAdmin重定向到应用程序根路径,而不是引擎根路径. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |