Catch Unknown action in Rails 3 for custom 404

前端 未结 4 1812
挽巷
挽巷 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:44

    Have you tried a catch all route?

    http://railscasts.com/episodes/46-catch-all-route

    The wildcard route that you are current using is a Bad Idea(tm).

    I would recommend defining the routes you care about, and then doing a catchall as the last line of routes.rb (routes defined first in routes.rb trump later definitions). Then you can render whatever page you want (and specify the 404 status code).

    Edit: If you really want to use your current approach... (although this seems like it could be deprecated)

    def rescue_action(exception) case exception when ActionNotFound, UnknownAction then # Handle these exceptions here else super end end

提交回复
热议问题