How to rescue page not found 404 in rails?

后端 未结 2 1717
闹比i
闹比i 2021-01-17 11:02

How to rescue page not found if user add wrong url in rails. I hope to show 404 page present in public folder if the url is invalid. How to do that? I was browsing about it

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 11:43

    Solution for Rails 4

    On routes.rb:

    get '*unmatched_route', to: 'application#not_found'
    

    On application_controller.rb:

    def not_found
      # Your exception handling code here
    end
    

提交回复
热议问题