title: Rails Include Admin access in before action
body: <p>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)</p>
  
  <p>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 <code>:show</code></p>
  
  <p>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.</p>
  
  <p>Many Thanks</p>
  
  <p>users_controller.rb</p>
  
  <pre><code>class UsersController &lt; ApplicationController
      before_action :logged_in_user, only: [:edit, :update, :show]
      before_action :correct_user, only: [:edit, :update, :show]
      before_action :admin_user, only: [:index]
  </code></pre>
  
  <p>define correct_user</p>
  
  <pre><code>def correct_user
    @user = User.find(params[:id])
    redirect_to(root_url) unless current_user?(@user)
  end
  </code></pre>
  
  <p>define admin_user</p>
  
  <pre><code> def admin_user
    if current_user.admin?
     flash.now[:success] = "Admin Access Granted"
    else
     redirect_to root_path
    end
   end
  </code></pre>
  
  <p>SESSIONS- sessions_helper.rb</p>
  
  <p>define current_user</p>
  
  <pre><code>  def current_user?(user)
     user == current_user
    end
  
  def current_user
      @current_user ||= User.find_by(id: session[:user_id])
  end
  </code></pre>