I wonder if anyone can help. I have below my current setup for an app where only an admin user should be able to see the user index: This works fine. Also non admin users are redirected to root This also works fine (although I would like to redirect them to their user profile)

The real problem is that I would like admin users to be able to visit the user profile page of any user from the index page link, but at the moment he can only visit his own page. I see that this is because the correct\_user before action lists `:show`

I have tried adding a :show action to the ':admin\_user before action', but it doesn't seem to help. Any suggestions as to how to fix this would be greatly appreciated.

Many Thanks

users\_controller.rb

```
class UsersController < ApplicationController
    before_action :logged_in_user, only: [:edit, :update, :show]
    before_action :correct_user, only: [:edit, :update, :show]
    before_action :admin_user, only: [:index]

```

define correct\_user

```
def correct_user
  @user = User.find(params[:id])
  redirect_to(root_url) unless current_user?(@user)
end

```

define admin\_user

```
 def admin_user
  if current_user.admin?
   flash.now[:success] = "Admin Access Granted"
  else
   redirect_to root_path
  end
 end

```

SESSIONS- sessions\_helper.rb

define current\_user

```
  def current_user?(user)
   user == current_user
  end

def current_user
    @current_user ||= User.find_by(id: session[:user_id])
end

```