Q:

Rails: How to check if user exsists in controller and if not redirect to other site

I want to check if a user exists in the show action of my UserController. If the user does not exists, the current user should be redirected to his on profile page (via show action). The problem is it gets redirected again and again and again until the browser stops it.
If I do not use respond_to |format| (so without the redirect) and only use set_user as an equivalent to User.find(params[:id]) the path shown in the browser is the wrong path but it shows the current user.
 UserController:

  def show
    respond_to do |format|
      if User.exists?(:id)
        @user = User.find(params[:id])
        format.html
      else
        set_user
        format.html {redirect_to @user, notice: 'User does not exist' }
      end
    end
  end

  private

  def set_user
    @user = current_user
  end

So I expect the correct path in the browser and the current user to be shown if a user does not exists. 
Either there is the wrong path showing the correct user or there is an infitine loop of redirections.

A:

might be a mistake the logic is correct ,  
def show
respond_to do |format|
  if User.exists?(params[:id])
    @user = User.find(params[:id])
    format.html
  else
    set_user
    format.html {redirect_to @user, notice: 'User does not exist' }
  end
end
end

