Take the 2-minute tour ×

When a user tries to connect via this method and it fails. How do I redirect_to? Thanks in Advance.

    class ApplicationController < ActionController::Base

  USER_NAME, PASSWORD = "admin", "admin"
  helper_method :authenticate

  def authenticate
      authenticate_or_request_with_http_basic do |user_name, password|
        user_name == USER_NAME && password == PASSWORD
      "HTTP Basic: Access denied"

      redirect_to root_path

share|improve this question
add comment

2 Answers

In the past, we've made authenticate a before_filter which will just perform the authenticate_or_request_with_http_basic, and then have our redirects/renders happen in their respective actions.

I just re-read your question & code sample. What exactly are you looking to have happen? A redirect on fail of the authentication?

Edit: I've never done this, but it seems like trying to follow the docs might be your best bet, in particular, the "more advanced basic example."

I ultimately don't know enough about the inner workings of basic auth, but it strikes me as it could also boil down to an Apache/(insert your awesome web server here) configuration. Someone will definitely correct me on that if I'm wrong.

share|improve this answer
Yup, basically when it fails, it goes to a white page with some text. How do I get it to just go back to root if it fails. –  RoR Sep 16 '10 at 1:55
And the before_filter I have is in my admin controller –  RoR Sep 16 '10 at 1:56
add comment

Your Answer


