For example typing: localhost:3000/absurd-non-existing-route
How do I get invalid routes to point to the main page of the application in Rails?
The solution presented here works pretty well
#Last route in routes.rb
match '*a', :to => 'errors#routing'
# errors_controller.rb
class ErrorsController < ApplicationController
def routing
render_404
end
end
On Rails 4+
Edit your routes.rb
file by adding a get "*path", to: redirect('/')
line just above the last end
as mentioned by user @ Rails: redirect all unknown routes to root_url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With