Search code examples
ruby-on-railshttp-redirectexceptionroutes

Redirect All Routing Errors to Root URL of the Application


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?


Solution

  • Use rescue_from in your ApplicationController to rescue ActionController::RoutingError and redirect to the home page when it happens.

    This will not work in Rails 3 currently. A ticket has been filed.