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.
精彩评论