Rails: redirect all unknown routes to root_url

后端 未结 5 1616
粉色の甜心
粉色の甜心 2020-11-30 23:02

Whenever a user hits the wrong page, rails shows 404.html from the public folder. However, I\'d like just to redirect the browser to the root page, without showing anything.

5条回答
  •  悲哀的现实
    2020-11-30 23:25

    You need create a controller to do that

    class RedirectsController 
    
      def index
        redirect_to root_url
      end
    end
    

    And in your routes

    map.connect '*', :controller => 'redirects', :action => 'index'
    

提交回复
热议问题