通過重定向到 Resring ActiveRecordRecordNotFound
你可以使用重定向來挽救 RecordNotFound 異常,而不是顯示錯誤頁面:
class ApplicationController < ActionController::Base
# your other stuff
rescue_from ActiveRecord::RecordNotFound do |exception|
redirect_to root_path, 404, alert: I18n.t("errors.record_not_found")
end
end