Catch Unknown action in Rails 3 for custom 404

前端 未结 4 2017
挽巷
挽巷 2021-01-31 12:14

I want to catch unknown action error in Rails 3, that shows \"Unknown Action\" error on development and the 404.html on production. I tried putting this rescue_from

4条回答
  •  不知归路
    2021-01-31 12:34

    Using a catch all route to handle 404 erros (as @Seth Jackson suggested) has one major drawback: if you use any Rails engines that define their own routes (such as Jammit) their routes will be ignored.

    Better and more compliant solution would be to use a Rack middleware that will catch 404 errors. In one of my projects, I've implemented such Rack middleware that reports these errors to Hoptoad. I've based my implementation on this one: https://github.com/vidibus/vidibus-routing_error, but instead of invoking my Rails app again to handle the 404 error, I do it in the Rack middleware and let nginx to show the 404 page.

提交回复
热议问题