Rails, Devise - Admin is trying to change another user profile, instead loading its own profile

Being completely new to Rails development, I try to understand the following: I am working with the Devise + Cancan + olify application to try to create authentication and user management. My normal user behavior is sorted, and I'm trying to get the admin user to be able to edit another user profile.

Currently, the admin user can list users and try to change another user profile. However, when you go to the edit page, even though the URL / route is correct for me, I am still provided with the information "currentuser" / admin in the form.

So, the scenario: UserId1 is the administrator. UserId1 is trying to change the profile of UserId2

Written as UserId1, the following route contains information for UserId1 instead of UserId2:   http://localhost:3000/d/users/edit.2

Here is the .rb route:

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

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

Here is a list of # index users:

<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>

Here is user_controller.rb:

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

Any help is appreciated!


Change 1

rake routes gives me the following:

    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
+4
source share
2 answers
<%= link_to edit_user_registration_path(user) %>

Your development route is still indicated, it should be:

<%= link_to edit_admin_user_path(user) %>

What is described in rake routes.

+1
source

, edit/2 edit.2. .2 Rails , 2 2.

rake routes , , - , .

+1

Source: https://habr.com/ru/post/1531685/


All Articles