【发布时间】:2014-08-25 03:44:18
【问题描述】:
所以我构建了一个身份验证方法,它充当控制器中其他方法的前置过滤器。基本上,如果用户未登录,我希望该方法重定向到根路径。这是我的 authenticate_user!过滤方法前:
def authenticate_user!
unless current_user
flash[:notice] = "Your session has ended. Please login again."
render js: "window.location.pathname = '#{root_path}'"
end
end
我遇到的问题是窗口本身没有重新加载,而是页面内的内容元素和显示的文本:“window.location.pathname = '/'”。我无法使用redirect_to(我找到了similar question here),因为它似乎只是将某个内容元素发送回root_path(而像导航栏这样的元素保持不变)。这就是为什么我一直在寻找一个完整的窗口重新加载。任何帮助将不胜感激。
使用服务器日志编辑:
Started GET "/projects/editHeader?fileName=test.csv" for 127.0.0.1 at 2014-07-04 10:37:21 -0400
Processing by ProjectsController#editHeader as TEXT
Parameters: {"fileName"=>"test.csv"}
Filter chain halted as :authenticate_user! rendered or redirected
Completed 200 OK in 2ms (Views: 0.1ms | ActiveRecord: 0.0ms)
Started GET "/projects/headerDataPreview?fileId=NaN" for 127.0.0.1 at 2014-07-04 10:37:21 -0400
Processing by ProjectsController#headerDataPreview as TEXT
Parameters: {"fileId"=>"NaN"}
Filter chain halted as :authenticate_user! rendered or redirected
Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
【问题讨论】:
标签: jquery ruby-on-rails ajax authentication render