views:

19

answers:

2

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

    class ApplicationController < 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 && password == PASSWORD
      end
    rescue
      "HTTP Basic: Access denied"
    else

      redirect_to root_path
    end

  end
end
A: 

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.

theIV
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
And the before_filter I have is in my admin controller
RoR