[rails5.1 / devise / administrative] Admin :: AdminUsers #index中的NameError

时间:2018-03-06 05:31:27

标签: ruby-on-rails devise ruby-on-rails-5 administrative

我正在努力解决错误(Admin :: AdminUsers#index中的NameError)

我正在使用设计和管理。 我必须设计控制器,所以设置一个控制器选项。

我的路线文件在这里。

parameter,ameError in Admin::AdminUsers#index

但是,在设置:controller后,访问admin / path时会出现ActionView::Template::Error (uninitialized constant AdminUsers::Session): 10: <nav class="navigation" role="navigation"> 11: <% Administrate::Namespace.new(namespace).resources.each do |resource| %> 12: <%= link_to( 13: display_resource_name(resource), 14: [namespace, resource_index_route_key(resource)], 15: class: "navigation__link navigation__link--#{nav_link_state(resource)}" 16: ) %>

错误明细:

・access to /admin (and login screen is shown)
・enter e-mail address and pass and submit
・Error occur (after login success)

复制程序:

Rails.application.routes.draw do
  devise_for :admin_users, path: :admin, skip: [:registration]
  namespace :admin do
    root to: "admin_users#index"
    resources :admin_users
  end
end

你能告诉我错误发生的原因吗?

在设置控制器参数之前,它工作正常。

                Prefix Verb   URI Pattern                           Controller#Action
    new_admin_user_session GET    /admin/sign_in(.:format)              devise/sessions#new
        admin_user_session POST   /admin/sign_in(.:format)              devise/sessions#create
destroy_admin_user_session DELETE /admin/sign_out(.:format)             devise/sessions#destroy
                      root GET    /                                     admin/admin_users#index
                admin_root GET    /admin(.:format)                      admin/admin_users#index
         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

rake路线相同

.collections

1 个答案:

答案 0 :(得分:1)

从我看到你正在设置:sessions => 'admin_users/sessions'我看不到任何符合你设置的路线。

我看到会话的路线正在跟随

    new_admin_user_session GET    /admin/sign_in(.:format)              devise/sessions#new
        admin_user_session POST   /admin/sign_in(.:format)              devise/sessions#create
destroy_admin_user_session DELETE /admin/sign_out(.:format)             devise/sessions#destroy

我认为您要添加devise/sessions,否则您必须创建一个与您的admin_users/sessions匹配的路线