【发布时间】:2016-09-23 13:54:33
【问题描述】:
如果身份验证失败,我会尝试重定向到 root_path。 目前,它只是使用 HTTP Basic: Access denied 更改页面的正文。
这是我的控制器:
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
研究了以下内容,但我仍然无法正确:
Rails: What is the location option for in the render method
【问题讨论】:
-
你为什么不用
redirect_to root_path? -
我试过但没用
-
它确实有效。您的情况可能有问题,而不是
redirect_to -
当然,我会继续努力
标签: ruby-on-rails authentication