Reputation: 151
I'm trying to redirect to the root_path if authentication fails. Currently, it's just changing the body of the page with HTTP Basic: Access denied.
Here is my controller:
class ProjectsController < ApplicationController
before_filter :http_basic_auth, only: [:show]
def http_basic_auth
if (authenticate_or_request_with_http_basic do |user, password| password == @project.passcode && user == @project.passcode end if @project.private?)
true
else
response.headers["Location"] = url_for(root_path)
end
end
end
Researched the following but I'm still not able to get it right:
Rails: What is the location option for in the render method
Upvotes: 0
Views: 2967
Reputation: 21
I you still haven't gotten this to work:
Try use authenticate_with_http_basic
in place of authenticate_or_request_with_http_basic
An snippet of an example from the Rails API documentation:
if user = authenticate_with_http_basic { |u, p| @account.users.authenticate(u, p) }
@current_user = user
else
request_http_basic_authentication
end
Upvotes: 2