ruby-on-rails – Rails,Devise – 管理员试图编辑另一个用户配置文件,而不是加载自己的配置文件

在使用Rails进行开发时相当新,我试图了解以下内容:

 我正在使用Devise Cancan olify应用程序尝试创建身份验证和用户管理.

我已经对一般用户行为进行了排序,并且我正在努力实现管理员用户能够编辑另一个用户配置文件.

目前,管理员用户可以列出用户并尝试编辑其他用户的个人资料.但是,当进入编辑页面时,尽管URL /路由对我来说是正确的,我仍然会在表单中看到“currentuser”/ admin信息.

简而言之,这个场景:
 UserId1是管理员
 UserId1正在尝试编辑UserId2的配置文件

记录为UserId1,以下路由为UserId1而不是UserId2带来详细信息:
    HTTP://本地主机:3000 / d /用户/ edit.2

这是routes.rb:

devise_for :users, :path_prefix => 'd', :controllers => { :registrations => 'registrations' }

namespace :admin do
  get '', to: 'dashboard#index', as: '/'
  resources :users
end

这是用户#index视图:

<table>
  <tbody>
    <% @users.each do |user| %>
      <tr>
        <td><%= user.id %></td>
        <td><%= user.first_name %></td>
        <td><%= user.last_name %></td>
        <td><%= user.email %></td>
        <td>
          <%= link_to edit_user_registration_path(user) %>
        </td>
        <td>
          <%= link_to registration_path(user),class: "red", :data => { :confirm => "Are you sure?" }, :method => :delete %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

这是users_controller.rb:

class Admin::UsersController < ApplicationController
  def index
    @users = User.all
  end
end

任何帮助表示赞赏!

编辑1

rake路线给我以下内容:

    Prefix Verb               URI Pattern                         Controller#Action
new_user_session          GET    /d/users/sign_in(.:format)          devise/sessions#new
user_session              POST   /d/users/sign_in(.:format)          devise/sessions#create
destroy_user_session      DELETE /d/users/sign_out(.:format)         devise/sessions#destroy
user_password             POST   /d/users/password(.:format)         devise/passwords#create
new_user_password         GET    /d/users/password/new(.:format)     devise/passwords#new
edit_user_password        GET    /d/users/password/edit(.:format)    devise/passwords#edit
                          PATCH  /d/users/password(.:format)         devise/passwords#update
                          PUT    /d/users/password(.:format)         devise/passwords#update
cancel_user_registration  GET    /d/users/cancel(.:format)           registrations#cancel
user_registration         POST   /d/users(.:format)                  registrations#create
new_user_registration     GET    /d/users/sign_up(.:format)          registrations#new
edit_user_registration    GET    /d/users/edit(.:format)             registrations#edit
                          PATCH  /d/users(.:format)                  registrations#update
                          PUT    /d/users(.:format)                  registrations#update
                          DELETE /d/users(.:format)                  registrations#destroy
user_confirmation         POST   /d/users/confirmation(.:format)     devise/confirmations#create
new_user_confirmation     GET    /d/users/confirmation/new(.:format) devise/confirmations#new
                          GET    /d/users/confirmation(.:format)     devise/confirmations#show
user_unlock               POST   /d/users/unlock(.:format)           devise/unlocks#create
new_user_unlock           GET    /d/users/unlock/new(.:format)       devise/unlocks#new
                          GET    /d/users/unlock(.:format)           devise/unlocks#show
root                      GET    /                                   pages#home
about                     GET    /about(.:format)                    pages#about
admin                     GET    /admin(.:format)                    admin/dashboard#index
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

最佳答案

<%= link_to edit_user_registration_path(user) %>

仍然指向你的设计路线,它应该是:

<%= link_to edit_admin_user_path(user) %>

在rake路线中描述了这一点.

点赞