title: Can't delete user from admin controller in Rails
body: <p>I have Users model with Devise gem. I'm trying to manage users through the Admin section and I get the following:</p>
  <ol>
  <li>I can create a new user.</li>
  <li>I can edit an already existing user.
  but I can't delete the user.</li>
  </ol>
  <p>After pressing the Destroy button, I'm redirected to the user information page.
  <a href="https://i.stack.imgur.com/j54l9.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p><strong>Controller:</strong></p>
  <blockquote>
  <p>admin/users_controller.rb</p>
  </blockquote>
  <pre><code>class Admin::UsersController &lt; ApplicationController
    layout &quot;admin_application&quot;
  
    before_action :set_user, only: [:show, :edit, :update, :destroy]
  
    def index
      @users = User.where.not(:id =&gt; current_user.id)
      #authorize @users
    end
  
    def show
      @user = User.find(params[:id])
      #authorize @user
    end
  
    def new
      @user = User.new
      #authorize @user
    end
  
    def create
      @user = User.new(user_params)
      #authorize @user
      if @user.save
        flash[:notice] = &quot;Successfully created User.&quot;
        redirect_to admin_users_path
      else
        render :action =&gt; 'new'
      end
    end
  
    def edit
      @user = User.find(params[:id])
      #authorize @user
    end
  
    def update
      @user = User.find(params[:id])
      #authorize @user
      params[:user].delete(:password) if params[:user][:password].blank?
      params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
  
      if @user.update(user_params)
        flash[:notice] = &quot;Successfully updated User.&quot;
        redirect_to admin_users_path
      else
        render :action =&gt; 'edit'
      end
    end
  
    def destroy
      @user.destroy
      redirect_to admin_users_path
      #@user = User.find(params[:id])
      #authorize @user
      #if @user.destroy
      #  flash[:notice] = &quot;Successfully deleted User.&quot;
      #  redirect_to admin_users_path
      #else
      #  redirect_to admin_users_path, flash: { error: &quot;User could not be deleted.&quot; }
      #end
    end
    private
  
    def set_user
      @user = User.find(params[:id])
    end
  
    def user_params
       params.require(:user).permit(:avatar, :first_name, :middle_name, :last_name, :username, :email, :role_id, :password, :password_confirmation)
    end
  end
  </code></pre>
  <p><strong>Routing</strong></p>
  <pre><code>Rails.application.routes.draw do
    root to: 'dashboard#index'
  
    # Users routes
    devise_for :users
    match '/users/:id', :to =&gt; 'dashboard#index', :as =&gt; :user, :via =&gt; :get # Show page for current_user
  
    # Admin routes
    namespace :admin do
      root to: 'dashboard#index'
  
      resources :users
      #match 'users/:id' =&gt; 'users#destroy', :via =&gt; :delete, :as =&gt; :admin_destroy_user
      resources :roles
    end
  end
  </code></pre>
  <p><strong>View section</strong></p>
  <blockquote>
  <p>Links in admin/users/show.html.haml</p>
  </blockquote>
  <pre><code>= link_to &quot;Edit&quot;, edit_admin_user_path(@user)
  = link_to &quot;Delete&quot;, admin_user_path(@user), data: { confirm: &quot;Are you sure?&quot; }, method: :delete
  </code></pre>
  <p>I figured out it:</p>
  <blockquote>
  <p>Althow if I try to edit user from <strong>Index</strong> page (lists all users),
  I'm redirecting to <strong>Show</strong> page. <a href="https://i.stack.imgur.com/RrRuA.png" rel="nofollow noreferrer">enter image description here</a> So
  I can manage profiles only from <strong>Show</strong> page, but button <strong>Back</strong> in
  browser show <strong>Edit</strong> page. So it is not important isue.</p>
  </blockquote>