开发者

Adding a status code to a :root redirect in Rails 3 causes annoying "You are being redirected" page

开发者 https://www.devze.com 2023-02-09 15:25 出处:网络
This code is being executed in a rescue_from. This works: redirect_to :root, :notice => \'Mice\' This causes a Rails 3 to generate a \"You are being redirected\" page:

This code is being executed in a rescue_from.

This works:

redirect_to :root, :notice => 'Mice'

This causes a Rails 3 to generate a "You are being redirected" page:

redirect_to 开发者_Go百科:root, :status => 403, :notice => 'Mice'

There have been similar questions, but I haven't seen anything recent or quite matching this scenario. Am I doing something wrong?


You're seeing this page because of the behavior of the browser. A 403 tells the browser that the request is completed with the status "Forbidden". You need to send a 3xx series status code to do a redirect. Using redirect_to without an explicit code sends a 302.

Note that if you use curl to test your second example you'll see the "You are being redirected" page for both a 302 and a 403 status code. redirect_to sends that back in the response regardless, but it's the browser that determines how to handle the request.

0

精彩评论

暂无评论...
验证码 换一张
取 消