title: Rails authenticate_or_request_with_http_basic
body: <p>When a user tries to connect via this method and it fails. How do I redirect_to? Thanks in Advance. </p>
  
  <pre><code>    class ApplicationController &lt; ActionController::Base
    protect_from_forgery
  
    USER_NAME, PASSWORD = "admin", "admin"
    helper_method :authenticate
  
    private
    def authenticate
      begin
        authenticate_or_request_with_http_basic do |user_name, password|
          user_name == USER_NAME &amp;&amp; password == PASSWORD
        end
      rescue
        "HTTP Basic: Access denied"
      else
  
        redirect_to root_path
      end
  
    end
  end
  </code></pre>