Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a status code to a :root redirect in Rails 3 causes annoying "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 :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?

like image 260
ClosureCowboy Avatar asked Jan 26 '26 20:01

ClosureCowboy


1 Answers

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.

like image 115
zetetic Avatar answered Jan 29 '26 11:01

zetetic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!