2017-04-16 24 views

回答

0

如果你的消息/內容不是動態的,我會建議自定義當前404.html頁面,而不是(無需添加match到您的路線,軌道會重定向到public/404.html默認情況下,在你的路由沒有找到任何URL)。

如果你想自定義的404頁,然後用@TiSer答案去。

1

這是最好不要使用404公共文件夾。

您可以添加在您的路線:

match "/404" => "errors#error404", via: [ :get, :post, :patch, :delete ]

比應用控制器,甚至更好的創造ErrorsController,添加render status: :not_found

此外,根據控制器添加自己的看法。

+0

我在routes.rb中添加了第一行。並在應用程序控制器中創建了'def error404',並在其中添加了'render status::not_found'。當我進入本地主機:3000/ssdsd。我'沒有路由符合項目ssdsd.' – user3576036

+0

@ user3576036根據路線第一線,你需要添加'高清error404'在ErrorsController代替ApplicationController中,因爲「錯誤#error404」鏈接到它(看看如何路由Rails中作品http://guides.rubyonrails.org/routing.html) – TiSer

+0

@ user3576036你做到了嗎? – TiSer

相關問題