-1

I tried to make a redirect to the '404' page.
In my filter I made a mistake and wrote:

redirect_to '404'

When i tested this, I had a strange result:
It seems like my browser was redirrected me back(I saw page, where I was before), like I'm wrote:

redirect_to :back

There are links to my picture about that:
http://oi58.tinypic.com/j62xht.jpg
http://itmages.ru/image/view/2873810/38c73083

My browser: Mozila Firefox 39.0.3

And i have a question: "Why it works?"

1 Answers1

2

Instead of redirecting to the 404 page, I would instead raise an error that Rails catches and automatically responds with a 404.

raise ActionController::RoutingError.new('Not Found')

Check out this question: How to redirect to a 404 in Rails?

With respect to why it's sending you back, I'd look at the redirect_to documentation. It seems like it's just creating a new request that happens to hit the same place you came from.

http://apidock.com/rails/ActionController/Redirecting/redirect_to

Community
  • 1
  • 1
Tom Prats
  • 7,364
  • 9
  • 47
  • 77