#<#<Class:0x00007efe19f773a8>:0x00007efe19f759b8>

时间:2019-09-06 19:36:34

标签: ruby-on-rails ruby ruby-on-rails-6

我尝试为自己的网站创建自己的管理区域,但是当我使用名称空间或范围时,我认为此错误

<td><%= link_to 'Show', admin_user %></td>

undefined method 'user_path' for #<#<Class:0x00007efe19f773a8>:0x00007efe19f759b8>

我已经尝试更改名称空间和范围,尝试使用其他路径名

我的routes.rb

  namespace :admin do
    root 'admins#index'
    resources :users, except: [:new, :create,:show]
  end

我的admin/users_controller.rb

module Admin
  class Admin::UsersController < Admin::AdminsController
    before_action :set_admin_user, only: [:show, :edit, :update, :destroy]

    def index
      @admin_users = User.all
    end
   #...
  end
end

rake routes

                               Prefix Verb     URI Pattern                                                                              Controller#Action
                                 root GET      /                                                                                        home#index
                     new_user_session GET      /users/sign_in(.:format)                                                                 devise/sessions#new
                         user_session POST     /users/sign_in(.:format)                                                                 devise/sessions#create
                 destroy_user_session DELETE   /users/sign_out(.:format)                                                                devise/sessions#destroy
      user_discord_omniauth_authorize GET|POST /users/auth/discord(.:format)                                                            users/omniauth_callbacks#passthru
       user_discord_omniauth_callback GET|POST /users/auth/discord/callback(.:format)                                                   users/omniauth_callbacks#discord
                           admin_root GET      /admin(.:format)                                                                         admin/admins#index
                          admin_users GET      /admin/users(.:format)                                                                   admin/users#index
                      edit_admin_user GET      /admin/users/:id/edit(.:format)                                                          admin/users#edit
                           admin_user PATCH    /admin/users/:id(.:format)                                                               admin/users#update
                                      PUT      /admin/users/:id(.:format)                                                               admin/users#update
                                      DELETE   /admin/users/:id(.:format)                                                               admin/users#destroy
                            test_test GET      /test/test(.:format)                                                                     test#test
                                 page GET      /pages/*id                                                                               high_voltage/pages#show

跟踪

21:55:19 web.1       | Started GET "/admin/users" for ::1 at 2019-09-06 21:55:19 +0200
21:55:19 web.1       |    (77.7ms)  SET NAMES utf8mb4,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
21:55:20 web.1       |    (20.4ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
21:55:20 web.1       | Processing by Admin::UsersController#index as HTML
21:55:20 web.1       |   User Load (0.6ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 4 ORDER BY `users`.`id` ASC LIMIT 1
21:55:20 web.1       |   Rendering admin/users/index.html.erb within layouts/application
21:55:20 web.1       |   User Load (3.0ms)  SELECT `users`.* FROM `users`
21:55:20 web.1       |   ↳ app/views/admin/users/index.html.erb:13
21:55:21 web.1       |   Rendered admin/users/index.html.erb within layouts/application (Duration: 439.4ms | Allocations: 125622)
21:55:21 web.1       | Completed 500 Internal Server Error in 859ms (ActiveRecord: 389.5ms | Allocations: 142302)
21:55:21 web.1       | 
21:55:21 web.1       | 
21:55:21 web.1       | 
21:55:21 web.1       | NoMethodError - undefined method `user_path' for #<#<Class:0x000055a920d2dbf0>:0x000055a920d277c8>:
21:55:21 web.1       |   app/views/admin/users/index.html.erb:15
21:55:21 web.1       |   app/views/admin/users/index.html.erb:13
21:55:21 web.1       | 
21:55:22 web.1       | Started POST "/__better_errors/f4aadb9eae251625/variables" for ::1 at 2019-09-06 21:55:22 +0200

1 个答案:

答案 0 :(得分:0)

我已经签入了沙箱项目,并且工作正常。

<td><%= link_to 'Show', admin_user_path(user_id) %></td>

这将导致users_controllers#show方法并呈现用户。