2011-03-22 63 views
5

如何呈現404,而不是NoMethodError在人民#顯示錯誤軌道3顯示404

代碼

def show 
    @person = Person.find(params[:id]) 
    respond_to do |format| 
    format.html # show.html.erb 
    format.xml { render :xml => @person } 
    end 
end 
+0

請參閱:http://stackoverflow.com/questions/2385799/how-to-redirect-to-a-404-in-rails/4983354#4983354 – Kelvin 2011-08-12 21:27:18

回答

10

NoMethodError將呈現在生產模式500,但是如果你也想渲染在發展方式的頭404種狀態,你可以做到以下幾點:

redirect_to :status => 404 

要渲染標準的404頁,你可以檢查出頂部nswer here.

+0

oh.nice。 NoMethodError將在生產模式下呈現404 – 2011-03-22 01:15:54

+0

對不起,它實際上會呈現500錯誤。無論哪種方式,它比你在開發模式中看到的更優雅。 – 2011-03-22 01:33:02

+0

那麼,如何渲染404?我不希望我的用戶看到500錯誤頁面。 – 2011-03-22 01:38:21