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.
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
I wasn't able to replicate @matthew-savage's results. However, per the Rails guide on route globbing and this question on another StackOverflow question, I solved this issue like so:
routes.rb
match "*gibberish", :to => "home#routing_error"
notice how I included text after the wildcard. The controller is fine as shown above:
controller/home_controller.rb
....
def routing_error
render text: "Not found, sorry", status: :not_found
end
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