通过重定向到 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