Search code examples
ruby-on-railsrubyactioncontroller

Rescue from routing error rails 3.1


How to rescue from RoutingError in rails 3.1 application. If i'm nt mistaken it was possible to use rescue_from RoutingError in application controller but now it's not possible.


Solution

  • There is no great way to handle it, but there are a few workarounds. The discussion here yields the following suggestion:

    Routes

    Add the following to your routes file:

    match "*", :to => "home#routing_error"

    and handle the error in this action:

    def routing_error
      render text: "Not found, sorry", status: :not_found
    end