2011-09-13 146 views

回答

11

這已經是生產中的默認行爲。在開發環境中,會顯示路由錯誤以便開發人員注意並修復它們。

如果您想嘗試它,請在生產模式下啓動服務器並檢查它。

$ script/rails s -e production 
0

您可以捕獲找到路由時引發的異常,然後呈現自定義頁面。讓我知道你是否需要幫助代碼。可能有很多其他的方法來做到這一點,但這絕對有效。

6

ApplicationController

rescue_from ActiveRecord::RecordNotFound, :with => :rescue404 
rescue_from ActionController::RoutingError, :with => :rescue404 

    def rescue404 
    #your custom method for errors, you can render anything you want there 
    end 
4

如果你不能很容易地運行在本地的生產模式,在config/environments/development.rb文件中設置consider_all_requests_local爲false。