當用戶嘗試通過此方法連接並失敗時。我如何redirect_to?提前致謝。Rails authenticate_or_request_with_http_basic
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
是的,基本上當它失敗時,它會轉到一個帶有文本的白頁。如果失敗,我怎麼才能回到根目錄。 – RoR 2010-09-16 01:55:44
而我擁有的before_filter在我的管理員控制器中 – RoR 2010-09-16 01:56:45