How can you redirect using a 302 from within the routes.rb file?
Asked
Active
Viewed 1.5k times
1 Answers
87
You can pass in the status to the redirect in the route statement. For example, to do a 302 redirect:
In the routes.rb
get '/old/path', to: redirect('/new/path', status: 302)
I hope this helps someone else!

Tom Rossi
- 11,604
- 5
- 65
- 96
-
6it's also possible to write `get '/make_donation' => redirect('/new/path', status: 302)` which is a bit shorter – trushkevich Nov 26 '15 at 19:24
-
You can also write it in a more declarative manner `get '/old/path', to: redirect('/new/path', status: :moved_permanently)` – Kruupös Dec 20 '21 at 15:20